我使用的是googlesheets4包,它使用gargle进行身份验证。我有一个定期运行的计划脚本,因此我需要设置非交互式身份验证。我尝试按照我找到的设置服务帐户令牌并使用它进行身份验证的所有说明进行操作,但似乎仍然无法使其正常工作。
我创建了一个服务帐户令牌,并将其存储在一个JSON文件中。然后我使用了以下命令:
gs4_auth (
scopes="https://www.googleapis.com/auth/spreadsheets",
path="/path/to/my/service/token.json")使用options(gargle_quiet = FALSE),我看到了以下内容:
trying token_fetch()
trying credentials_service_account()
adding 'userinfo.email' scope
service account email: email_address@project.iam.gserviceaccount.com一切似乎都很好用!
但是当我尝试运行gs <- gs4_find(my_sheet_name)时,我得到了以下结果:
attempt from: googledrive
trying token_fetch()
trying credentials_service_account()
Error: Argument 'txt' must be a JSON string, URL or file.
trying credentials_app_default()
trying credentials_gce()
trying credentials_byo_oauth()
Error: inherits(token, "Token2.0") is not TRUE
trying credentials_user_oauth2()
Gargle2.0 initialize
attempt from: googledrive
adding 'userinfo.email' scope
loading token from the cache
no matching token in the cache
initiating new token...And然后它会打开一个浏览器窗口,要求我登录到我的帐户。看起来credentials_service_account()第一次成功了,但是当它再次被调用时,它就失败了。这里我漏掉了什么?
提前感谢!
发布于 2021-02-10 01:07:56
现在这个问题已经解决了,并在googlesheets4包的Github页面上回复了这篇文章的副本!
事实证明,gs4_find实际上是googledrive::drive_find的包装器。因此,为了让服务令牌对此函数起作用,我需要使用googledrive而不是googlesheets4进行身份验证。如果您同时使用googlesheets4和googledrive,甚至还有一个关于协调身份验证的完整article here。
对于我的特定用例,我实际上只是将谷歌工作表I硬编码到我的脚本中,而不是使用gs4_find进行名称查找,从而完全避免了使用googledrive。我觉得这对我的目的就足够了。
https://stackoverflow.com/questions/66109351
复制相似问题