我使用 R 的包“twitteR”和“ROAuth”来访问 Twitter API。 我尝试使用此 R 代码来注册我的 R 会话:
tw<-OAuthFactory$new(consumerKey="mykeyhere",consumerSecret="mysecrethere",
requestURL="http://api.twitter.com/oauth/request_token",
accessURL="http://api.twitter.com/oauth/access_token",
authURL="http://api.twitter.com/oauth/authorize")
tw<-handshake()
我使用http而不是https,因为后者给了我SSL认证失败的错误。 然后,我输入从给定 URL 获取的 PIN 码并在 Twitter 上注册:
registerTwitterOAuth(tw)
上述命令的结果是:
[1] TRUE
我认为我使用 OAuth 注册成功。 但是,例如,当我尝试访问受保护用户的个人资料时,
getURL("http://api.twitter.com/1/followers/ids.json?cursor=-1&user_id=XXXXXXXX")
我得到了这个:
[1] "{\"error\":\"Not authorized\",\"request\":\"\\/1\\/followers\\/ids.json?cursor=-1&user_id=XXXXXXXX\"}"
我还使用以下方法检查了我的验证:
getURL("http://api.twitter.com/1/account/verify_credentials.json")
这就是结果:
[1] "{\"error\":\"Could not authenticate you.\",\"request\":\"\\/1\\/account\\/verify_credentials.json\"}"
你介意帮我吗? 非常感谢。
您应该使用
getUser(...)
、searchTwitter(...)
、tw$OAuthRequest(...)
等,而不是自己直接使用getURL(...)
,因为getURL()
不包含会话上下文(使用registerTwitterOAuth
注册)。