google-api - Google API 给出未经授权的 token 错误

标签 google-api service-accounts google-workspace google-directory-api

我们在 GCP 中托管了一个应用程序,它使用 GSuite API 将用户从 GSuite 同步到我们的应用程序,反之亦然。它曾经运行良好,直到最近我们的一些客户开始遇到问题。

我们开始得到

401 unauthorized. "Client is unauthorized to retrieve access tokens using this method, or client not authorized for any of the scopes requested."

我们的应用程序和授予的权限列表都没有变化。以下是授予的 api 访问权限列表:-

https://apps-apis.google.com/a/feeds/domain,
https://www.googleapis.com/auth/activity,
https://www.googleapis.com/auth/admin.directory.group,
https://www.googleapis.com/auth/admin.directory.orgunit, 
https://www.googleapis.com/auth/admin.directory.user,**
https://www.googleapis.com/auth/admin.directory.user.readonly,
https://www.googleapis.com/auth/drive,
https://www.googleapis.com/auth/drive.appdata,
https://www.googleapis.com/auth/drive.file,
https://www.googleapis.com/auth/drive.metadata,
https://www.googleapis.com/auth/drive.metadata.readonly,
https://www.googleapis.com/auth/admin.directory.rolemanagement.readonly,
https://www.googleapis.com/auth/admin.directory.rolemanagement,
https://www.googleapis.com/auth/admin.directory.device.chromeos.readonly,
https://www.googleapis.com/auth/admin.directory.device.chromeos,
https://www.googleapis.com/auth/drive.apps.readonly,
https://www.googleapis.com/auth/drive.photos.readonly,
https://www.googleapis.com/auth/drive.scripts  

受影响的 GSuite 域在昨天之前一直运行良好。还有一些域仍然可以正常工作。

有人可以建议问题出在哪里吗? API最近有什么变化吗?任何帮助将不胜感激。

最佳答案

"Client is unauthorized to retrieve access tokens using this method, or client not authorized for any of the scopes requested."

有多种方法可以向 Google 进行身份验证。

  • 基于网络的应用程序
  • 原生应用
  • 移动应用
  • 和服务帐户

您为这些类型创建的客户端与使用它们的代码不同。您在上面看到的消息意味着您使用的代码与您创建的客户端类型不匹配。

确保您的代码专为与服务帐户一起使用而设计,并确保您从谷歌开发者控制台下载的凭据文件实际上是服务帐户的凭据。

为什么它以前工作并突然停止我不能告诉你这是一个错误,如果你的代码与你的凭据类型不匹配,你将永远遇到这个错误。

最后一个选项是仔细检查是否已在 Google 开发人员控制台中为您的服务帐户项目启用所有这些 API。

关于google-api - Google API 给出未经授权的 token 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54667981/

相关文章:

google-apps-script - Google OAuth 同意屏幕验证状态 未发布

python - 使用 python 在 Gmail 中发送邮件

google-api - 401 访问被拒绝。您无权读取事件记录

google-cloud-storage - 如何更改 Google Compute Engine 服务帐户的范围以将数据写入 Google Cloud Storage 存储桶?

google-apps-script - 以 "unlisted"模式在 GSuite 市场上发布附加组件

c# - Google Analytics 管理 Api 插入目标 : 403 Insufficient permission .net

javascript - 基本 JavaScript 警报未显示

javascript - 如何使用 JavaScript 下载带有 Google Picker 的 Google 表格?

google-drive-api - 当用户的存储空间即将用完时,Google Workspace 提醒或 API 会收到通知

google-cloud-platform - 使用 Colaboratory 永久允许 Google Cloud SDK 访问您的 Google 帐户