Unauthorized error with ROAuth

北城余情 提交于 2020-01-14 19:10:29

问题


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:


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.



来源:https://stackoverflow.com/questions/17964444/unauthorized-error-with-roauth

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!