R cron 作业无法编辑 googlesheet - 授权问题

问题描述 投票:0回答:1

我有一个 cron 作业,它使用

range_clear
包中的
sheet_write
googlesheets4
函数编辑 googlesheet。这是我设置权限的方法:

library(googlesheets4)

# Set authentication token to be stored in a folder called `.secrets`
options(gargle_oauth_cache = ".secrets")

# Authenticate manually
gs4_auth()

# If successful, the previous step stores a token file.
# Check that a file has been created with:
list.files(".secrets/")

# Check that the non-interactive authentication works by first deauthorizing:
gs4_deauth()

# Authenticate using token. If no browser opens, the authentication works.
gs4_auth(cache = ".secrets", email = "[email protected]")

它每天都运行良好大约一个月,直到它开始无法编辑 gsheet,原因在here我认为在“为什么我的方法失败”下。 然后,我决定按照链接 (devtools::install_github("tidyverse/googlesheets4")) 中的说明重新安装 googlesheets4 软件包,这样我就可以从

retry
功能中受益。我完全按照上面的说明再次设置了权限。该脚本在本地运行良好(并使用
retry
),但作业本身系统性地失败并抛出此错误:

i The googlesheets4 package is using a cached token for
  '[email protected]'.
Error in `gs4_get_impl_()`:
! Client error: (403) PERMISSION_DENIED
* Client does not have sufficient permission. This can happen because the OAuth
  token does not have the right scopes, the client doesn't have permission, or
  the API has not been enabled for the client project.
* Request had insufficient authentication scopes.

Error details:
* reason: ACCESS_TOKEN_SCOPE_INSUFFICIENT

关于我应该如何进行有什么建议吗?

r cron tidyverse googlesheets4
1个回答
0
投票

好吧,这就是它的作用:直接在 cron 作业的开头添加此代码片段 ==>

gs4_auth(cache = ".secrets", email = "[email protected]")

© www.soinside.com 2019 - 2024. All rights reserved.