我正在尝试在Google Api(https://developers.google.com/admin-sdk/directory/v1/reference/groups/list)中获取域名列表 .
我正在使用“域范围授权”,并拥有一个服务帐户,Web应用程序向Google提出所有请求 . admin-sdk要求请求用户是管理员,因此我冒充定给定域上的管理员用户 .
这适用于(https://developers.google.com/admin-sdk/directory/v1/reference/users/get),但是当我尝试使用组api时,它会像这样失败:
{
"error": {
"errors": [
{
"domain": "global",
"reason": "forbidden",
"message": "Not Authorized to access this resource/api"
}
],
"code": 403,
"message": "Not Authorized to access this resource/api"
}
}
我已经检查了域管理员的权限是否已委托给服务帐户 . 我还检查了我可以访问组列表,同时以域管理员身份登录 .
任何帮助或提示都非常感谢 . 提前致谢
2 回答
您需要添加阅读组的范围 .
首先,请确保您已正确执行此documentation中的步骤,包括如何Instantiate an Admin SDK Directory service object的此步骤 .
这一点非常重要,因为这会向您展示如何使用OAuth 2.0和服务帐户的凭据进行API请求,以执行Google Apps域范围的委派 .
有关更多信息,请查看以下相关的SO问题:
Google_Service_Directory - (403) Not Authorized to access this resource/api
Received error “Not Authorized to access this resource/api” when trying to use Google Directory API and Service Account Authentication