You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何添加ServiceAccount到位置组并通过API获取评论及解决邀请无法接受问题

将ServiceAccount添加至位置组并获取评论的解决方案

1. 添加ServiceAccount到位置组

  • 先确保已启用Business Profile API,并为ServiceAccount分配Business Profile Manager相关权限(至少需要评论读取权限,建议分配OWNER或MANAGER角色)。
  • 获取目标位置组的资源ID(格式:accounts/{accountId}/locationsGroups/{locationGroupId}),调用accounts.locationsGroups.members.create接口,传入ServiceAccount的邮箱(格式:[service-account-id]@[project-id].iam.gserviceaccount.com),并指定角色为ROLE_MANAGER或ROLE_OWNER。
  • 关于邀请接受:由于ServiceAccount没有邮箱收件箱,无法通过API自动接受邀请,必须通过拥有该位置组所有权的主账号(如你的G Suite/个人GMB账号)登录Business Profile Manager后台,找到位置组的邀请列表,手动接受ServiceAccount的加入申请。

2. 通过API获取位置评论

  • 准备ServiceAccount的密钥文件(JSON格式,从Google Cloud Console下载)。
  • 在代码中使用服务账号身份验证,以Python为例:
    from google.oauth2 import service_account
    from googleapiclient.discovery import build
    
    SCOPES = ['https://www.googleapis.com/auth/business.manage']
    SERVICE_ACCOUNT_FILE = 'path/to/your/service-account-key.json'
    
    credentials = service_account.Credentials.from_service_account_file(
        SERVICE_ACCOUNT_FILE, scopes=SCOPES)
    
    service = build('mybusiness', 'v4', credentials=credentials)
    
    # 替换为你的账号ID和位置ID
    location_name = 'accounts/123456789/locations/987654321'
    reviews = service.accounts().locations().reviews().list(parent=location_name).execute()
    
    print(reviews)
    
  • 调用accounts.locations.reviews.list接口时,传入目标位置的资源名称作为parent参数,即可获取该位置的所有评论数据,包括评论内容、评分、用户信息等。

注意:如果调用接口时返回权限错误,需检查ServiceAccount的角色是否正确,以及邀请是否已被手动接受。

内容的提问来源于stack exchange,提问作者Ruslan

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.12 17:22:45