0

我正在编写一个简单的脚本,该脚本用于googlesheets4读取一些数据,然后使用漱口水来验证 API 调用。我遇到了gs4_auth()验证错误用户的问题。

我首先运行gs4_auth("example@example.com")以使用我的 Google 帐户进行身份验证,一切正常。

gargle::credentials_service_account()稍后,我通过使用本地服务帐户 json 密钥生成令牌来验证我的 API 调用。这也很好用。

当我在之前对 API 调用进行身份验证后尝试再次运行脚本时,就会出现问题。当我运行gs4_auth()它时,它使用服务帐户凭据,并且read_sheet()调用返回 403 错误。

有没有办法强制gs4_auth()不使用服务帐户凭据。服务帐户的电子邮件与传递给的电子邮件不同,gs4_auth()因此我不希望它使用不匹配的凭据。

我运行了身份验证,options(options(gargle_verbosity = "debug")它提供了以下输出:

> gs4_auth(email = 'example@example.com')
trying `token_fetch()`
trying `credentials_service_account()`
Error caught by `token_fetch()`:
Argument 'txt' must be a JSON string, URL or file.
trying `credentials_external_account()`
aws.ec2metadata not installed; can't detect whether running on EC2 instance
trying `credentials_app_default()`
file exists at ADC path:
/Users/path-to-service-account-credentials/json-key-filename.json
ADC cred type: "service_account"
trying `credentials_service_account()`
adding "userinfo.email" scope
service account email: example-service-account@project.iam.gserviceaccount.com

随后的 403 错误发生是因为 example@example.com 可以访问 google 工作表,但 example-service-account@project.iam.gserviceaccount.com 没有。

4

0 回答 0