首页 > 解决方案 > Google Cloud 组设置 - 授权失败(python 应用)

问题描述

我正在尝试阅读属于 google 组的用户。我相信问题不在于应用程序,而是我找不到的一些配置。情况描述如下:

- Group: group-tmp
  - created by user user1@company.com
  - members:
    - user1@company.com (owner)
    - group-service@quickstart-...iam... (owner) <-- service user

- Project: quickstart-XXXXX
  - owners:
    - user1@company.com (owner)
    - group-service@quickstart-...iam... (owner)
  - config:
    - api enabled using this website: https://console.cloud.google.com/apis/library/groupssettings.googleapis.com?project=grupo-tmp

使用以下 python 代码:

#!/usr/bin/python
from __future__ import print_function

import json

import httplib2
from googleapiclient.discovery import build
from oauth2client.service_account import ServiceAccountCredentials

with open('service_secrets.json') as f:
    json_loaded = json.load(f)

credentials = ServiceAccountCredentials.from_json_keyfile_dict(
    json_loaded,
    scopes=["https://www.googleapis.com/auth/apps.groups.settings"])

http = httplib2.Http()
http = credentials.authorize(http)

service = build('groupssettings', 'v1', http=http)

groups = service.groups()

print('step 4')

g = groups.get(groupUniqueId="group-tmp@company.com").execute()

print('step 5')

它总是在第 4 步和第 5 步之间失败,并显示以下错误消息:

googleapiclient.errors.HttpError: <HttpError 401 when requesting https://www.googleapis.com/groups/v1/groups/group-tmp@company.com?alt=json returned "Authorization Failed". Details: "Authorization Failed">

标签: python-3.xgoogle-cloud-platform

解决方案


推荐阅读