Twitter Authentication with R

January 15, 2016

(This article was first published on R Tutorials – ThinkToStart, and kindly contributed to R-bloggers)

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 on topics such as: Data science, Big Data, R jobs, visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...

If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...

Comments are closed.

Search R-bloggers


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)