使用Google Pub/Sub订阅Google Meet通知遇权限问题,求USER_ID获取方法
如何获取Google Cloud Identity的USER_ID以配置Google Pub/Sub接收Meet通知
你遇到的问题是因为Google Pub/Sub要求的目标资源路径里的USER_ID是Cloud Identity的用户唯一ID,不是邮箱地址。以下几种方法可以获取正确的USER_ID:
方法1:用gcloud命令行工具快速查询
直接在终端运行以下命令(替换成你的邮箱):
gcloud identity users describe your-email@gmail.com
命令输出里的id字段值就是你需要的USER_ID。
方法2:通过Google Workspace Admin SDK查询
如果用Python代码,可以调用Admin SDK的Users.get接口,传入邮箱作为userKey,返回结果中的id字段即为USER_ID。示例代码如下:
from googleapiclient.discovery import build from google.oauth2 import service_account # 加载服务账号密钥(需提前配置好Admin SDK权限) credentials = service_account.Credentials.from_service_account_file( 'service-account-key.json', scopes=['https://www.googleapis.com/auth/admin.directory.user.readonly'] ) # 替换成你的Workspace管理员邮箱 delegated_credentials = credentials.with_subject('admin@your-domain.com') service = build('admin', 'directory_v1', credentials=delegated_credentials) # 替换成目标用户邮箱 user = service.users().get(userKey='your-email@gmail.com').execute() print("USER_ID:", user['id'])
注意:使用这个方法需要你的服务账号有Workspace Admin SDK的访问权限,并且已启用域范围授权。
方法3:通过Cloud Identity控制台手动查找
- 登录Google Cloud Console,进入Cloud Identity的用户管理页面
- 搜索目标用户的邮箱,进入用户详情页
- 在用户信息里找到“唯一ID”(可能显示为User ID),这个就是需要的USER_ID
另外,还要确保配置Pub/Sub的账号拥有Cloud Identity Viewer角色(或包含cloudidentity.users.get权限的自定义角色),否则即使USER_ID正确,也会出现权限拒绝错误。
内容的提问来源于stack exchange,提问作者Harry
相关产品推荐
相关产品推荐

