使用Discovery API获取Google Group成员时group_id无效报错求助
报错原因
Google Cloud Identity Groups API要求的group_id为群组的唯一数字资源ID,你传入的群组邮箱、纯文本名称都不是合法参数,因此触发2033错误。
正确获取群组资源路径的方式
不需要手动拼接groups/{group_id}格式的路径,你可以通过两种方式直接获取完整的合法父路径:
- 命令行查询:完成gcloud身份认证后执行以下命令,返回结果中的
name字段就是你需要的父路径:gcloud identity groups lookup --group-key-id=my_google_group@my_organization.com - 代码内直接查询:调用
groups.lookup接口先获取资源路径,再执行成员查询,修正后代码如下:
# 先查询群组对应的资源路径 lookup_response = service.groups().lookup(groupKey_id="my_google_group@my_organization.com").execute() group_parent_path = lookup_response["name"] # 再查询群组成员 request = service.groups().memberships().searchTransitiveMemberships(parent=group_parent_path)
注意事项
- 执行查询的身份需要拥有对应群组的查看权限,以及Cloud Identity API的调用权限
- 查询时必须传入完整的群组邮箱作为参数,不能只填邮箱前缀
内容的提问来源于stack exchange,提问作者Tristan Bilot
相关产品推荐
相关产品推荐

