2011-09-14 71 views
2

我用R的软件包'twitteR'和'ROAuth'来访问Twitter API。 我想这个R代码里面注册我的R对话:使用Twitter API的OAuth身份验证失败!

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码:

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\"}" 

你介意帮我吗? 非常感谢。

+0

您是否尝试使用此功能向您的Twitter帐户发布信息?如果是这样的结果是什么? – Kevin

回答

2

你应该使用getUser(...)searchTwitter(...)tw$OAuthRequest(...)等,而不是自己直接使用getURL(...)因为getURL()不包含会话上下文(寄存器使用registerTwitterOAuth)。

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