Error: oauth_listener() needs an interactive environment in R
我正在尝试通过连接Twitter的命令行编写R脚本。当我通过R-Studio运行代码时,它可以连接到Twitter并获取推文。但是,当我通过命令行运行脚本时,出现以下错误:
1 | Error: oauth_listener() needs an interactive environment. |
要解决此问题,我跑了R-studio一次,并以以下方式保存了环境变量:
1 2 3 4 5 6 7 8 9 | 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") } |
现在我得到一个错误:
1 | Error in get_oauth_sig() : OAuth has not been registered for this session |
我也尝试通过以下方式保存身份验证会话:
1 2 3 4 5 6 7 8 9 10 11 12 13 | 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中搜索流
1 | searchTwitter("love", n=10) |
我认为您需要使用与交互式登录不同的身份验证模型。不幸的是,我不是这些方面的专家,但是从Twitter文档看来,您想要"仅应用程序身份验证"。
https://dev.twitter.com/oauth/application-only