在 Google Cloud 中具有所有者角色的用户在使用 Gmail Api 时收到 403

User with Owner Role in Google Cloud gets 403 when Using Gmail Api

使用 gcloud 我使用我的电子邮件地址 me@gmail.com 登录到终端 window。这个项目启用了 Gmail API,我是这个配置的所有者。 gcloud auth list 显示

`Active Account`
`*me@gmail.com`

gcloud projects get-iam-policy $PROJECT 显示 me@gmail.com 作为所有者

我在项目中创建了一个 Oauth client/secret。我的意图是生成一个访问令牌以通过终端

对 gmail API 进行身份验证
`curl -H "Authorization: Bearer $(gcloud auth print-access-token)" https://gmail.googleapis.com/gmail/v1/users/me/labels`. (me is my actual email address)

这样做会给我一个 403。但是,我可以使用 https://developers.google.com/oauthplayground/ 并获得我特定范围的令牌。我需要将 Oauth Client Id 传递给 print-access-token 吗?为什么所有者没有对已启用的 API 中所有可能操作的权限?

编辑:我尝试使用 auth application-default 凭据进行登录,结果相同。

TIA

您的范围不正确。您需要正确地确定您的凭据范围。首先使用此命令在您的凭据中添加您想要的范围

gcloud auth application-default login \
  --scopes='https://mail.google.com/',\
  'https://www.googleapis.com/auth/cloud-platform'

然后使用应用程序默认 access_token 调用您的服务

curl -H "Authorization: Bearer $(gcloud auth application-default print-access-token)" \ 
  https://gmail.googleapis.com/gmail/v1/users/me/labels`. (me is my actual email address)

它应该会更好用。