【问题标题】:Non-interactive auto-refresh stale OAuth Token with Googlesheets package使用 Googlesheets 包的非交互式自动刷新陈旧 OAuth 令牌
【发布时间】:2016-11-25 17:45:52
【问题描述】:

我正在尝试自动运行 r 脚本以每小时下载一个私人 Google 表格。当我以交互方式使用 R 时,它总是可以正常工作。在我使用 launchd 自动执行脚本后的第一个小时内,它也可以正常工作。

在我开始使用 launchd 自动化它一小时后它停止工作。我认为问题在于一小时后访问令牌发生了变化,并且非交互式版本没有等待 OAuth 令牌的自动刷新。这是我从错误报告中得到的错误:

自动刷新陈旧的 OAuth 令牌。 gzfile(文件,模式)中的错误:无法打开连接 调用:gs_auth ... -> -> cache_token -> saveRDS -> gzfile 另外:警告信息: 在 gzfile(file, mode) 中: 无法打开压缩文件“.httr-oauth”,可能的原因是“权限被拒绝” 执行停止

我正在使用 Jenny Bryan 的 googlesheets 包。这是我最初用于注册工作表,然后保存 oAuth 令牌的代码:

gToken <- gs_auth() # Run this the first time to get the oAuth information
saveRDS(gToken, "/Users/…/gToken.rds") # Save the oAuth information for non-interactive use

然后我在使用launchd 自动化的文件中使用以下脚本:

gs_auth(token = "/Users/…/gToken.rds")

使用launchd 自动运行脚本时如何避免此错误?

【问题讨论】:

    标签: launchd r-googlesheets non-interactive


    【解决方案1】:

    我不知道launchd,但是当我想从Windows 任务规划器自动运行R 脚本时,我遇到了同样的问题。将“缓存”属性值更改为 FALSE 对我有用 [1]:https://i.stack.imgur.com/pprlC.png

    您可以在这里找到解决方案:https://github.com/jennybc/googlesheets/issues/262

    为了在浏览器中进行一次身份验证以获取令牌文件,我这样做了:

    token_file <- gs_auth(new_user = TRUE, cache = FALSE)
    saveRDS(token_file, "googlesheets_token.rds")
    

    之后通过以下方式自动登录:

    gs_auth(token = paste0(path_scripts, "googlesheets_token.rds"), 
    verbose = TRUE, cache = FALSE)
    

    【讨论】:

      猜你喜欢
      • 2016-01-21
      • 2018-09-29
      • 2016-09-10
      • 2013-11-12
      • 1970-01-01
      • 2017-06-24
      • 1970-01-01
      • 2020-05-05
      • 2016-02-05
      相关资源
      最近更新 更多