首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >非交互式服务帐号令牌身份验证不起作用

非交互式服务帐号令牌身份验证不起作用
EN

Stack Overflow用户
提问于 2021-02-09 05:05:16
回答 1查看 81关注 0票数 0

我使用的是googlesheets4包,它使用gargle进行身份验证。我有一个定期运行的计划脚本,因此我需要设置非交互式身份验证。我尝试按照我找到的设置服务帐户令牌并使用它进行身份验证的所有说明进行操作,但似乎仍然无法使其正常工作。

我创建了一个服务帐户令牌,并将其存储在一个JSON文件中。然后我使用了以下命令:

代码语言:javascript
复制
gs4_auth (
   scopes="https://www.googleapis.com/auth/spreadsheets", 
   path="/path/to/my/service/token.json")

使用options(gargle_quiet = FALSE),我看到了以下内容:

代码语言:javascript
复制
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)时,我得到了以下结果:

代码语言:javascript
复制
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()第一次成功了,但是当它再次被调用时,它就失败了。这里我漏掉了什么?

提前感谢!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-02-10 01:07:56

现在这个问题已经解决了,并在googlesheets4包的Github页面上回复了这篇文章的副本!

事实证明,gs4_find实际上是googledrive::drive_find的包装器。因此,为了让服务令牌对此函数起作用,我需要使用googledrive而不是googlesheets4进行身份验证。如果您同时使用googlesheets4googledrive,甚至还有一个关于协调身份验证的完整article here

对于我的特定用例,我实际上只是将谷歌工作表I硬编码到我的脚本中,而不是使用gs4_find进行名称查找,从而完全避免了使用googledrive。我觉得这对我的目的就足够了。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/66109351

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档