OAuth Authentication with Twitter API failed!

泪湿孤枕 提交于 2019-12-07 22:10:46

问题


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()

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)

The result of the above command was:

[1] TRUE

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")

I got this:

[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")

And this was the result:

[1] "{\"error\":\"Could not authenticate you.\",\"request\":\"\\/1\\/account\\/verify_credentials.json\"}"

Would you mind helping me please? Thank you very much.


回答1:


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).

example of tw$OAuthRequest http://goo.gl/6IwdU



来源:https://stackoverflow.com/questions/7411215/oauth-authentication-with-twitter-api-failed

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