【问题标题】:Error: oauth_listener() needs an interactive environment in R错误:oauth_listener() 需要 R 中的交互式环境
【发布时间】:2015-07-14 19:48:07
【问题描述】:

我正在尝试通过命令行连接到 Twitter 的 R 脚本。当我通过 R-Studio 运行代码时,它能够连接到 Twitter 并获取推文。但是,当我通过命令行运行脚本时,出现以下错误:

Error: oauth_listener() needs an interactive environment.

为了解决这个问题,我通过 R-studio 运行了一次,并以下列方式保存了环境变量:

if(file.exists("./token_file"))
  {
    load("./token_file")
  }
  else
  {
     token <- setup_twitter_oauth(consumerKey,consumerSecret,access_token=NULL, access_secret=NULL)
    save(token,file="./token_file")
  }

现在我得到一个错误:

Error in get_oauth_sig() : OAuth has not been registered for this session

我也尝试通过以下方式保存身份验证会话:

requestURL <- "https://api.twitter.com/oauth/request_token"
  accessURL <- "https://api.twitter.com/oauth/access_token"
  authURL <- "https://api.twitter.com/oauth/authorize"
if(file.exists("./auth_file"))
  {
    load("./auth_file")
  }
  else
  {
    my_oauth <- OAuthFactory$new(consumerKey = consumerKey, consumerSecret = consumerSecret, 
                               requestURL = requestURL, accessURL = accessURL, authURL = authURL)
    save(my_oauth,file ="./auth_file")
  }

但是我仍然收到上述错误。有没有办法让 R 通过命令行连接到 Twitter?

我正在使用twitteR 包。

我使用函数在twitter中搜索流

searchTwitter("love", n=10)

【问题讨论】:

  • 您可以发布用于获取 twitter 提要的代码吗?
  • 您是否尝试过在“setup_twitter_oauth()”函数中设置“access_token”和“access_secret”参数?不需要交互式环境 (more here)
  • @NicE 我试过了。我收到以下错误:尚未为此会话注册 OAuth

标签: r twitter oauth oauth-2.0 twitter-oauth


【解决方案1】:

我相信您需要使用与交互式登录不同的身份验证模型。不幸的是,我不是这些事情的专家,但似乎从 Twitter 文档中您想要“仅应用程序身份验证”。

https://dev.twitter.com/oauth/application-only

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-01-08
    • 2016-02-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-11-24
    • 2022-11-29
    相关资源
    最近更新 更多