OAuth authentication with Twitter's API using R

3.6k views Asked by At

I am exploring the Twitter API.

I am using the ROAuth and twitteR packages in R.

I reach a point where I think things are going well:

To enable the connection, please direct your web browser to: 
https://api.twitter.com/oauth/authorize?oauth_token=XXXXX
When complete, record the PIN given to you and provide it here: XX

So far so good. Now, I am ready to see some Twitter timelines:

> my_tweets <- userTimeline('someTimeline')

Unfortunately, I get:

Error in InterfaceObj$doAPICall(cmd, params, method, ...) : 
  OAuth authentication is required with Twitter's API v1.1

I have been researching what this means. I feel like my OAuth authentication is appropriate. Why would I be getting this error?

Is there some issue with the version of the API I am using?

2

There are 2 answers

0
user3400008 On

I see that you were successful accessing (aka handshaking). I assume your handshaking code would be similar to the following line.

Cred$handshake(cainfo = system.file("CurlSSL", "your_certificate.pem", package = "RCurl") )

Then I assume you registered Twitter OAuth by using the following line, which you said that it was successful.

registerTwitterOAuth(Cred)

Then your userTimeline should include the pem file you created before.

my_tweets <- userTimeline('someTimeline', cainfo="your_certificate.pem", n=200)
0
rischan On

You can follow this step:

reqURL <- "https://api.twitter.com/oauth/request_token"
accessURL <- "https://api.twitter.com/oauth/access_token"
authURL <- "https://api.twitter.com/oauth/authorize"
consumerKey <- "Mjn6tdsadsadkasdklad2SV1l"
consumerSecret <- "58Z7Eldsdfaslkf;asldsaoeorjkfksaVCQtvri"
twitCred <- OAuthFactory$new(consumerKey=consumerKey,
                             consumerSecret=consumerSecret,
                             requestURL=reqURL,
                             accessURL=accessURL,
                             authURL=authURL)
twitCred$handshake()

After you run this code you will see in R console message like this :

To enable the connection, please direct your web browser to: 
https://api.twitter.com/oauth/authorize?oauth_token=scmVODruosvz6Tdsdadadasdsa
When complete, record the PIN given to you and provide it here:

Just paste the link to your browser then authorize app, last one you will get the PIN code, just copy and paste the PIN code to your R console.

registerTwitterOAuth(twitCred)

R console will show TRUE if you success.

user <- getUser("xxx")
userTimeline(user, n=20, maxID=NULL, sinceID=NULL, includeRts=FALSE)

If still any problem just try to show your package version and update to the last version

sessionInfo()
update.packages("twitteR")

The last version for twitteR is 1.1.7 => http://cran.r-project.org/web/packages/twitteR/index.html