ROAuth 出现未经授权的错误 [英] Unauthorized error with ROAuth
问题描述
我正在使用 streamR 包从 Twitter Streaming API 中提取推文.这一直工作到最近.现在 - 每次握手时我都会收到错误消息.
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
我尝试在 dev.twitter.com 上重新创建一个新应用程序,但仍然遇到相同的错误.我曾尝试更改回调 URL 和访问级别 - 但没有用.我也尝试使用来自 github 的 ROAuth 的 master 分支.知道我哪里出错了吗?我正在使用 R 3.0.1
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
推荐答案
我遇到了同样的问题.以下命令序列解决了问题:
I had the same problem. The following sequence of commands solved the problem:
consumerKey <- ...
consumerSecret <- ...
twitCred <- getTwitterOAuth(consumer_key= consumerKey, consumer_secret=consumerSecret)
searchTwitter()
注意我没有使用registerTwitterOAuth(twitCred)
.我想如果你想保存并稍后加载 twitCred
你必须在加载后使用 registerTwitterOAuth(twitCred)
.
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.
我希望这会有所帮助.
附言由于我使用的是 Mac,我没有使用 cacert.pem
文件.我认为它只是 Windows 所必需的.
P.S. Since I am using a Mac, I didn't use the cacert.pem
file. I think it is just required for Windows.
这篇关于ROAuth 出现未经授权的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!