【发布时间】:2021-04-23 22:05:37
【问题描述】:
目标:我的 python 网络应用程序从客户那里访问谷歌用户的信息。他们已经向服务帐户提供了访问 admin.directory.user.readonly 范围的授权,并且我使用此服务帐户 JSON 文件作为我的应用程序的凭据。 credential_path = os.path.join(os.path.dirname(app.instance_path), 'cre.json') os.environ['GOOGLE_APPLICATION_CREDENTIALS'] = credential_path
SCOPES = ['https://www.googleapis.com/auth/admin.directory.user.readonly']
PATH_TO_CREDENTIALS = os.environ.get('GOOGLE_APPLICATION_CREDENTIALS')
GET_CREDENTIALS = PATH_TO_CREDENTIALS
PASS_CREDENTIALS = service_account.Credentials.from_service_account_file(GET_CREDENTIALS, scopes=SCOPES)
service = build('admin', 'directory_v1', credentials=PASS_CREDENTIALS)
# Call the Admin SDK Directory API
print('Getting the first 10 users in the domain')
results = service.users().list(customer='customer.com', domain='customer.com', maxResults=10, orderBy='email').execute()
users = results.get('users', [])
for user in users:
print(u'{0} ({1})'.format(user['primaryEmail'], user['name']['fullName']))
我得到:
googleapiclient.errors.HttpError: <HttpError 400 when requesting https://admin.googleapis.com/admin/directory/v1/users?customer=nidec-ga.com&domain=nidec-ga.com&maxResults=10&orderBy=email&alt=json returned "Bad Request". Details: "Bad Request">
知道可能出了什么问题吗?
【问题讨论】:
标签: python flask google-cloud-platform google-oauth api-key