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 apps.twitter.com/ 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: http://127.0.0.1:1410
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! library(devtools) install_github("twitteR", username="geoffjentry") library(twitteR)
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" setup_twitter_oauth(api_key,api_secret)
And that´s it.
If you want to test your authentication just try to get some tweets with: