Twitter Authentication with R

[This article was first published on R Tutorials – ThinkToStart, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

This article is just a small summary about the authentication process with Twitter. Its about creating the Twitter app and doing the handshake cause you have to do it every time you want to get data from Twitter with R.

Since Twitter released the Version 1.1 of their API a OAuth handshake is necessary for every request you do. So we have to verify our app.

First we need to create an app at Twitter.

Got to and log in with your Twitter Account.

Now you can see your Profile picture in the upper right corner and a drop-down menu. In this menu you can find “My Applications”.

Click on it and then on “Create new application”.

You can name your Application whatever you want and also set Description on whatever you want. Twitter requires a valid URL for the website, but you can also enter a placeholder there.

As the Callback URL enter:

Twitter Authentication R

Click on Create you´ll get redirected to a screen with all the OAuth setting of your new App. Just leave this window in the background; we´ll need it later

Before we go on, make sure you have installed the newest version of the twitteR package from github.

Therefore you can use the following code:

install.packages(c("devtools", "rjson", "bit64", "httr"))

#RESTART R session!

install_github("twitteR", username="geoffjentry")

Now the twitteR package is up-to-date and we can use the new and very easy setup_twitter_oauth() function which uses the httr package.


Twitter Authentication with R:

First you have to get your api_key and your api_secret as well as your access_token and access_token_secret from your app settings on Twitter. Just click on the “API key” tab to see them.

api_key <- "YOUR API KEY"

api_secret <- "YOUR API SECRET"

access_token <- "YOUR ACCESS TOKEN"

access_token_secret <- "YOUR ACCESS TOKEN SECRET"


And that´s it.

If you want to test your authentication just try to get some tweets with:






The post Twitter Authentication with R appeared first on ThinkToStart.

To leave a comment for the author, please follow the link and comment on their blog: R Tutorials – ThinkToStart. offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)