python-3.x - 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">
解决方案
推荐阅读
- ubuntu - 如何使用 rsynch 通过 ssh 隧道远程更新文件?
- php - 如何使单个值更新 SQL 查询与 Wordpress 中的 $wpdb 类一起使用?
- django - 创建它后无法立即从数据库中找到对象
- enums - 从其名称而不是值创建枚举
- javascript - 使用 JavaScript 在经过一定时间后运行函数?
- php - 有没有一种简单的方法可以使用 FILTER_SANITIZE_NUMBER_INT 来验证电话号码(以表格形式)?
- arrays - 我是否需要从内存中将数组的基地址加载到此 MIPS 代码中的临时寄存器中?
- python - 在字典和列表中查找整数
- javascript - Ionic 3 JavaScript 堆内存不足
- fft - 我想通过 gnuradio-companion (i)fft 吗?