Google API提供未经授权的令牌错误

时间:2019-02-13 10:31:23

标签: google-api service-accounts gsuite google-directory-api

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

我们开始获得

  

401未经授权。 “客户无权使用此方法检索访问令牌,或者客户无权进行任何请求的范围。”

我们的应用程序没有任何变化,授予的权限列表中也没有变化。以下是授予的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最近有变化吗?任何帮助将不胜感激。

1 个答案:

答案 0 :(得分:-1)

  

“客户无权使用此方法检索访问令牌,或者客户无权进行任何请求的范围。”

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

  • 基于Web的应用程序
  • 本机应用
  • 移动应用
  • 和服务帐户

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

确保您的代码设计用于服务帐户,并确保您从google开发者控制台下载的凭据文件实际上是服务帐户的凭据。

为什么以前可以正常工作并突然停止,所以我无法告诉您这是一个错误,如果您的代码与您的凭据类型不匹配,您将总是会收到此错误。

最后一个选择是再次检查是否在Google开发者控制台中为您的服务帐户项目启用了所有这些api。