Twitter Data API access in RSTUDIO

Get access to the Twitter API: https://developer.twitter.com/en/apply-for-access

Create an APP, as documented here: https://developer.twitter.com/en/apps

Annotation 2019-11-05 073528

Click on “Details”, then “Keys and tokens”

Annotation 2019-11-05 073800

(The credentials listed above will not work)

Use the generated credentials as below:

library(httr)
library(jsonlite)
myapp = oauth_app("twitter",
key="G87rxMsrngAiSkE6ZlWwXHd4n",secret="zSjjnEProRRFqDqEKNHWcOZU1CTQF4G2Q01yy7qqkwCeXJUDo1")
sig = sign_oauth1.0(myapp,
token = "1129684236733227008-EsgKImtzWxtvawBHPDBG01LKp9O413",
token_secret = "4YKBlKXTgerRiocYWrTW8XTaVWd8O91TzPhE1UJ2AggCu")
homeTL = GET("https://api.twitter.com/1.1/statuses/home_timeline.json", sig)
json1 = content(homeTL)
json2 = jsonlite::fromJSON(toJSON(json1))
json2[1:2,1:4]
view raw con_twit.R hosted with ❤ by GitHub

So where did the URL in GET come from?

The API Reference contains these instructions: https://developer.twitter.com/en/docs/tweets/timelines/api-reference/get-statuses-home_timeline

Annotation 2019-11-05 080500.png

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.