如何在Google Admin中通过serviceId查询对应的关联服务?
如何通过serviceId查询Google Admin关联服务
当你调用Google Admin SDK的Privileges.list接口时,部分权限条目可能仅返回serviceId而缺失serviceName,可以通过以下两种方式查询对应的关联服务:
1. 遍历全量权限数据匹配serviceId
同一个服务的所有权限条目共享唯一的serviceId,因此你可以:
- 调用
Privileges.list接口时不设置任何过滤条件,获取所有权限的完整数据集 - 在返回结果中,筛选出所有与目标
serviceId一致的条目,其中必然存在包含serviceName的条目,以此关联到对应的服务名称。
比如你提供的示例中,serviceId=02w5ecyt3pkeyqi对应的权限MANAGE_PLAY_FOR_WORK_STORE,和第一个条目里的play_for_work服务属于同一服务,通过遍历就能完成关联。
2. 使用Services.list接口直接查询服务信息
Google Admin Directory API提供的Services.list接口,专门用于获取Google Workspace所有服务的元数据,其中包含serviceId、serviceName以及服务显示名称等完整字段。你可以直接调用该接口,根据目标serviceId匹配到对应的服务。
以下是调用示例(基于Google Client Library的伪代码):
from googleapiclient.discovery import build # 初始化Admin Directory服务 admin_service = build('admin', 'directory_v1', credentials=your_auth_credentials) # 获取所有服务列表 services_response = admin_service.services().list(customer='my_customer').execute() all_services = services_response.get('items', []) # 查找目标serviceId对应的服务 target_service_id = "02w5ecyt3pkeyqi" for service in all_services: if service['serviceId'] == target_service_id: print(f"服务标识:{service['serviceName']},显示名称:{service['serviceDisplayName']}") break
注意事项
- 调用
Services.list接口需要你的授权账号拥有Google Workspace服务配置的查看权限 serviceId是服务的唯一标识,同一服务的所有权限条目会共用此ID,因此两种方法都能可靠关联到服务信息
内容的提问来源于stack exchange,提问作者Cristi Moldovan
相关产品推荐
相关产品推荐

