【问题标题】:oauth_listener() needs an interactive environment (execution halted)oauth_listener() 需要一个交互式环境(执行停止)
【发布时间】:2016-07-09 00:52:21
【问题描述】:

尝试批量运行 R 脚本(见下文),我收到错误 oauth_listener() 需要一个交互式环境,然后它停止执行。我发现 oath_listener() 是 httr 包的一部分。代码在 R Studio 中运行良好,只是不能作为 Rscript.exe 运行?

require(RODBC)
require(RSQLite)
require(RGoogleAnalytics)
require(httpuv)
require(httr)

client.secret <- "xxx"
client.id <- "xxx.apps.googleusercontent.com"

token <- Auth(client.id,client.secret)
save(token,file="./token_file")
ValidateToken(token)

【问题讨论】:

    标签: r google-analytics-api httr


    【解决方案1】:

    也许以交互方式运行一次以保存令牌文件,然后在您想以批处理模式运行时加载令牌文件。您可以使用...测试它是否存在

    if(file.exists("./token_file")){
      load("./token_file")
    }else{
      token <- Auth(client.id,client.secret)
    }
    

    【讨论】:

    • 这是个好主意,但是 - 仍然遇到同样的错误:/
    • httr 也会自动为您执行此操作
    • @AustinTrombley 你能解决这个问题吗?
    • 是的,我必须将令牌文件保存到静态位置/不是临时文件夹
    【解决方案2】:

    当您在 R Studio 或 R 中运行您的 R 脚本时,它有一个已定义的工作目录,您可以通过以下命令检查:getwd()
    当您在批处理文件中运行脚本时,它可能有不同的工作目录,因此找不到您需要的令牌文件。
    因此,您可以先检查在 R Studio 中运行命令 getwd() 的目录,然后在脚本中插入命令 setwd("same working directory from R Studio") 以将目录设置为您在 RStudio 中使用的目录。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-07-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-02-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多