尽管它不是我的主要语言,但我使用R将日常ETL中的结果发布到Google Sheets工作表中。因为这将是一个永久运行的计划作业,所以我在犹豫是否使用交互式流程从R验证Google Drive。我从我的Google Drive帐户凭据获得了JSON的路径,但当我通过时
gs4_deauth()
gs4_has_token()
gs4_auth(email=<email-string>, path = jsonlite::fromJSON(<path-to-json>), cache = NULL)它抛出以下错误:
[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凭据更简单。
发布于 2021-05-07 03:09:08
如果是服务帐户凭据
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可以通过以下方式重用:
token <- googlesheets4::gs4_token()
googledrive::drive_auth(token = token)
googledrive::drive_has_token()
[1] TRUEhttps://stackoverflow.com/questions/63289979
复制相似问题