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

使用Google_Service_MyBusinessBusinessInformation获取locations报read_mask无效如何解决

错误原因

你遇到的400错误是因为readMask中填写的字段不符合新版Google My Business Business Information v1接口的Location资源字段规范,你当前使用的user.display_name、photo都不是该接口支持的合法字段。

PHP客户端正确写法

readMask需要填写你需要返回的Location资源字段,多个字段用英文逗号分隔,不能添加多余空格,也不能使用不存在的字段。
常用合法字段包括:name(门店资源唯一标识)、title(门店名称)、address(门店地址)、phoneNumbers(联系电话)、websiteUri(官网地址)、regularHours(营业时间)、photos(门店照片)等,你可以根据需求自行增删字段。

修正后的完整代码示例:

$my_business_account = new Google_Service_MyBusinessAccountManagement($client);
$list_accounts_response = $my_business_account->accounts->listAccounts();
$account = $list_accounts_response[0];
$mybusinessService = new Google_Service_MyBusinessBusinessInformation($client);
$locations = $mybusinessService->accounts_locations;
$queryParams = [
    "pageSize" => 10,
    // 按实际需求填写需要返回的字段,禁止使用通配符*
    'readMask' => "name,title,address,phoneNumbers,websiteUri,regularHours,photos"
];
$locationsList = $locations->listAccountsLocations($account->name, $queryParams);

Postman/REST请求正确写法

  • 请求方法:GET
  • 请求URL:https://mybusinessbusinessinformation.googleapis.com/v1/accounts/你的账号ID/locations
  • 查询参数:添加readMask参数,值和上述PHP写法一致,比如readMask=name,title,address,photos
  • 请求头:添加Authorization: Bearer 你的OAuth访问令牌

注意:readMask不支持通配符*,必须明确列出所有你需要返回的字段,字段名必须和官方定义的Location资源字段完全一致。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.09.30 01:45:01