【问题标题】:OAuth Authentication with Twitter API failed!使用 Twitter API 的 OAuth 身份验证失败!
【发布时间】:2011-11-16 16:40:04
【问题描述】:

我使用 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\"}"

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

【问题讨论】:

  • 您是否尝试使用此工具向您的 Twitter 帐户发帖?如果有,结果如何?

标签: r twitter twitter-oauth


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 2015-03-13
    • 2021-11-14
    • 2013-04-15
    • 1970-01-01
    • 2011-06-18
    • 2011-06-10
    • 2014-04-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多