Unauthorized error with ROAuth

1.3k views Asked by At

I am using the streamR package to pull tweets from the Twitter Streaming API. This was working fine till recently. Now - I am getting the error whenever I do a handshake.

> library(ROAuth)
> reqURL <- "https://api.twitter.com/oauth/request_token"
> accessURL <- "https://api.twitter.com/oauth/access_token"
> authURL <- "https://api.twitter.com/oauth/authorize"
> consumerKey <- "<myconsumerkey>"
> consumerSecret <- "myconsumersecret>"
> my_oauth <- OAuthFactory$new(consumerKey=consumerKey,consumerSecret=consumerSecret,requestURL=reqURL,accessURL=accessURL,authURL=authURL)
> my_oauth$handshake(cainfo = system.file("CurlSSL", "cacert.pem", package = "RCurl"))
Error: Unauthorized

I have tried recreating a new application on dev.twitter.com and I still get the same error. I have tried changing the callback URL and the access levels - but no use. I have also tried using the master branch of ROAuth from github. Any idea where I am going wrong? I am using R 3.0.1

1

There are 1 answers

0
pbahr On

I had the same problem. The following sequence of commands solved the problem:

consumerKey <- ...
consumerSecret <- ...
twitCred <- getTwitterOAuth(consumer_key= consumerKey, consumer_secret=consumerSecret)
searchTwitter()

Notice I didn't use registerTwitterOAuth(twitCred). I think if you wanna save and later load twitCred you have to use registerTwitterOAuth(twitCred) after loading.

I hope this helps.

P.S. Since I am using a Mac, I didn't use the cacert.pem file. I think it is just required for Windows.