【问题标题】:twitteR ROAuth handshake error: not generating the PIN option推特 ROAuth 握手错误:未生成 PIN 选项
【发布时间】:2013-08-12 00:09:13
【问题描述】:

这个问题实际上回答了所有与 twitteR ROAuth 问题相关的问题:

TwitteR, ROAuth and Windows: register OK, but certificate verify failed

TwitteR 和 ROAuth 之前都可以在我的电脑上完美运行。但是代码块不再生成 PIN 选项。它弹出以下内容:

twitCred$handshake(cainfo="cacert.pem")
Error: Unauthorized

以前 twitCred$handshake(cainfo="cacert.pem") 指向:

To enable the connection, please direct your web browser to: 
https://api.twitter.com/oauth/authorize?oauth_token=SevxcpCh9riO5PPrI8U8____
When complete, record the PIN given to you

我在 spark rstudio 服务器中尝试了我的代码。然后代码完美运行(生成输入 PIN 的选项,目前在我的电脑中没有生成)。代码是:

require(twitteR)
require(ROAuth)

requestURL <- "https://api.twitter.com/oauth/request_token"
accessURL <- "https://api.twitter.com/oauth/access_token"
authURL <- "https://api.twitter.com/oauth/authorize"
consumerKey <- "______________"
consumerSecret <- "___________________"


twitCred <- OAuthFactory$new(consumerKey=consumerKey,
consumerSecret=consumerSecret, requestURL=requestURL, accessURL=accessURL,
authURL=authURL)


setwd("/home/__")
download.file(url="http://curl.haxx.se/ca/cacert.pem", destfile="cacert.pem")
twitCred$handshake(cainfo="cacert.pem")
  To enable the connection, please direct your web browser to: 
  https://api.twitter.com/oauth/authorize?oauth_token=SevxcpCh9riO5PPrI8U8____
  When complete, record the PIN given to you

感谢任何帮助。

【问题讨论】:

  • 现在 twitCred$handshake 在我的电脑上工作。我猜 twitter 开发者网站由于过度使用而在有限的时间内阻止了该 ip。

标签: r twitter twitter-oauth roauth


【解决方案1】:

Twitter 应用程序必须具有读、写权限。这就是让我绕过授权错误的原因。请注意以下说明:

http://dev.twitter.com 创建一个 Twitter 应用程序。确保授予应用读取、写入和直接发送消息的权限。 请注意 Twitter 应用页面中的以下值:“API 密钥”、“API 机密”、“访问令牌”和“访问令牌机密”。

install.packages(c("devtools", "rjson", "bit64", "httr")) 确保此时重新启动您的 R 会话

库(开发工具) install_github(“推特”,用户名=“geoffjentry”) 图书馆(推特) setup_twitter_oauth("API key", "API secret")

API 密钥和 API 机密来自上面的 Twitter 应用页面。这将引导您完成 httr 的 OAuth 身份验证过程。我建议您查看 Token in httr 的手册页,了解它如何处理缓存。

你应该准备好了!

【讨论】:

    【解决方案2】:
    twitCred$handshake(cainfo = system.file("CurlSSL", "cacert.pem", package = "RCurl"))
    

    这对我有用。

    【讨论】:

    • 你能不能再补充一点来解释一下为什么这行得通(例如,告诉用户他们做错了什么?)
    • 如果一个人开始连续下载大量推文,Twitter API 有时会阻止 IP 地址。否则,如果使用受限,此代码可以正常工作。
    猜你喜欢
    • 2012-07-28
    • 2020-05-04
    • 2012-03-11
    • 1970-01-01
    • 2012-11-24
    • 1970-01-01
    • 2021-01-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多