使用 Twitter API 的 OAuth 身份验证失败! [英] OAuth Authentication with Twitter API failed!
问题描述
我使用 R 的包twitteR"和ROAuth"来访问 Twitter API.我试过这个 R 代码来注册我的 R 会话:
I used R's packages 'twitteR' and 'ROAuth' to access Twitter API. I tried this R code to register my R session:
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 获得并在 Twitter 上注册的 PIN 码:
I used http instead of https because the latter gave me an error of SSL certification fail. Then, I enter a PIN code obtained from a given URL and registered with Twitter:
registerTwitterOAuth(tw)
以上命令的结果是:
[1] TRUE
我认为我使用 OAuth 成功注册.但是,例如,当我尝试访问受保护用户的个人资料时,
I think that I successfully registered using OAuth. However, when I tried to access protected users' profiles, for example,
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\"}"
我还使用以下方法检查了我的验证:
I also checked my verification by using:
getURL("http://api.twitter.com/1/account/verify_credentials.json")
这就是结果:
[1] "{\"error\":\"Could not authenticate you.\",\"request\":\"\\/1\\/account\\/verify_credentials.json\"}"
你介意帮我一下吗?非常感谢.
Would you mind helping me please? Thank you very much.
推荐答案
你应该使用 getUser(...)
,searchTwitter(...)
,tw$OAuthRequest(...)
等等,而不是自己直接使用 getURL(...)
因为 getURL()
不包含 session上下文(使用 registerTwitterOAuth
注册).
You should use getUser(...)
,searchTwitter(...)
,tw$OAuthRequest(...)
and so on instead of directly use getURL(...)
by yourself because getURL()
does not contain session context (which register using registerTwitterOAuth
).
tw$OAuthRequest 示例 http://goo.gl/6IwdU
这篇关于使用 Twitter API 的 OAuth 身份验证失败!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!