首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用json路径的googlesheets4非交互式身份验证

使用json路径的googlesheets4非交互式身份验证
EN

Stack Overflow用户
提问于 2020-08-07 02:49:21
回答 1查看 411关注 0票数 3

尽管它不是我的主要语言,但我使用R将日常ETL中的结果发布到Google Sheets工作表中。因为这将是一个永久运行的计划作业,所以我在犹豫是否使用交互式流程从R验证Google Drive。我从我的Google Drive帐户凭据获得了JSON的路径,但当我通过时

代码语言:javascript
复制
gs4_deauth()
gs4_has_token()
gs4_auth(email=<email-string>, path = jsonlite::fromJSON(<path-to-json>), cache = NULL)

它抛出以下错误:

代码语言:javascript
复制
[1] FALSE
Error: Can't get Google credentials.
Are you running googlesheets4 in a non-interactive session? Consider:
  * `gs4_deauth()` to prevent the attempt to get credentials.
  * Call `gs4_auth()` directly with all necessary specifics.
See gargle's "Non-interactive auth" vignette for more details:
https://gargle.r-lib.org/articles/non-interactive-auth.html
Execution halted

由于错误消息没有提供太多细节,我想知道是否有人对此有经验,或者知道为什么会发生这种情况?我之所以使用gs4_deauth(),是因为我最初是使用交互流登录的,但现在希望确保非交互式身份验证有效。

顺便说一句,从json凭据文件创建令牌对象最不痛苦的方法是什么?我认为这可能比直接使用path参数重复传递json凭据更简单。

EN

回答 1

Stack Overflow用户

发布于 2021-05-07 03:09:08

如果是服务帐户凭据

代码语言:javascript
复制
googlesheets4::gs4_auth(
  path = "service_accout.json",
  scopes = "https://www.googleapis.com/auth/spreadsheets.readonly"
)

## NOTE: the spreadsheet is shared with the service account
s <- googlesheets4::read_sheet(ID_OF_YOUR_SPREADSHEET)

Token可以通过以下方式重用:

代码语言:javascript
复制
token <- googlesheets4::gs4_token()
googledrive::drive_auth(token = token)
googledrive::drive_has_token()
[1] TRUE
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/63289979

复制
相关文章

相似问题

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