【发布时间】: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