MyBusiness Business information API中的字段掩码错误

huangapple go评论69阅读模式
英文:

Field mask error on MyBusiness Business information API

问题

尝试使用“我的业务业务信息API”查询位置以及稍后获取评论的方法。在使用Oath Playground尝试时,所有尝试都只给出错误。尝试向ChatGpt询问,但所有建议也导致错误。

所以尝试列出特定帐户的位置:

https://mybusinessbusinessinformation.googleapis.com/v1/accounts/{accountId}/locations?fields=locations(name)

给出了以下错误:

{
  "error": {
    "status": "INVALID_ARGUMENT",
    "message": "Request contains an invalid argument.",
    "code": 400,
    "details": [
      {
        "fieldViolations": [
          {
            "field": "read_mask",
            "description": "Field is required"
          }
        ],
        "@type": "type.googleapis.com/google.rpc.BadRequest"
      }
    ]
  }
}

还尝试了这个请求:https://mybusinessbusinessinformation.googleapis.com/v1/accounts/{accountId}/locations?read_mask=locations.name,但给出了类似的错误:

{
  "error": {
    "status": "INVALID_ARGUMENT",
    "message": "Request contains an invalid argument.",
    "code": 400,
    "details": [
      {
        "fieldViolations": [
          {
            "field": "read_mask",
            "description": "Invalid field mask provided"
          }
        ],
        "@type": "type.googleapis.com/google.rpc.BadRequest"
      }
    ]
  }
}

文档并未提供明确的提示,说明该如何使用:https://developers.google.com/my-business/reference/businessinformation/rest/v1/accounts.locations/list。对于需要花费多少时间来弄清楚谷歌API的工作方式感到有些沮丧。

英文:

Trying to figure out how to query the My Business Business Information API to get the locations and later on the reviews. Using the Oath Playground to try this out but all attempts just gives me errors. Tried asking ChatGpt but all suggestions from that also gives error.

So trying to list the locations for a specific account:

https://mybusinessbusinessinformation.googleapis.com/v1/accounts/{accountId}/locations?fields=locations(name)

Gives me this error:

{
  "error": {
    "status": "INVALID_ARGUMENT", 
    "message": "Request contains an invalid argument.", 
    "code": 400, 
    "details": [
      {
        "fieldViolations": [
          {
            "field": "read_mask", 
            "description": "Field is required"
          }
        ], 
        "@type": "type.googleapis.com/google.rpc.BadRequest"
      }
    ]
  }
}

Also tried this request: https://mybusinessbusinessinformation.googleapis.com/v1/accounts/{accountId}/locations?read_mask=locations.name

But that gives similar error:

{
  "error": {
    "status": "INVALID_ARGUMENT", 
    "message": "Request contains an invalid argument.", 
    "code": 400, 
    "details": [
      {
        "fieldViolations": [
          {
            "field": "read_mask", 
            "description": "Invalid field mask provided"
          }
        ], 
        "@type": "type.googleapis.com/google.rpc.BadRequest"
      }
    ]
  }
}

The documentation gives nu direct hints on what to use: https://developers.google.com/my-business/reference/businessinformation/rest/v1/accounts.locations/list and getting a bit frustrated about how much time needs to be spent trying to figure Google APIs workings out.

答案1

得分: 1

我遇到了相同的问题。我在文档中找到了解决方案:

https://github.com/googleapis/google-api-php-client-services/blob/main/src/MyBusinessBusinessInformation/Resource/AccountsLocations.php

这很狡猾-文档中有一个错误。readMask 是一个必需的参数,在文档中被列在“可选参数”列表的最底部...在第83-84行:

@opt_param string readMask Required. Read mask to specify what will be returned in the response.

所以 readMask 是一个必填字段。它是一个字符串,应该是一个用逗号分隔的字段列表,用于指定响应中返回的内容。您可以查看 Location 对象,以了解您可以返回哪些字段,或者在我的示例下方略微查看(这部分由您决定,抱歉):

https://github.com/googleapis/google-api-php-client-services/blob/main/src/MyBusinessBusinessInformation/Location.php

这对于每种情况都可能不会有所帮助,但是对于使用 PHP、使用客户端库的情况,它可能看起来像这样:

// 构建客户端之后...
$business_info = new google\Service\MyBusinessBusinessInformation($client);

$locations_response = $business_info->accounts_locations->listAccountsLocations($accountName, [
    'readMask' => 'labels,name,storeCode,title,websiteUri'
]);

if(count($locations_response->locations)){
    // 在此处进行操作
    foreach($locations_response->locations as $location){
        // 访问位置对象
    }
}

希望对你有所帮助!

英文:

I had the same issue. I found the solution in the documentation here:

https://github.com/googleapis/google-api-php-client-services/blob/main/src/MyBusinessBusinessInformation/Resource/AccountsLocations.php

It's very sneaky- there is an error in the documentation. readMask is a required parameter, that in the documentation is listed at the very bottom of the 'optional parameters' list...On line 83-84:

@opt_param string readMask Required. Read mask to specify what will be returned in the response.

So readMask is a required field. It is a string, and it should be a comma-delineated list of fields you would like to returned with the response. You can look at the Location object to get an idea of what fields you can return, or look a bit below in my example (that part's up to you, sorry):

https://github.com/googleapis/google-api-php-client-services/blob/main/src/MyBusinessBusinessInformation/Location.php

This won't be helpful for every use case but- for PHP, using the client library, it would look something like this:

//  after building client...
$business_info = new google\Service\MyBusinessBusinessInformation($client);

$locations_response = $business_info->accounts_locations->listAccountsLocations($accountName, [
    'readMask' => 'labels,name,storeCode,title,websiteUri'
]);

if(count($locations_response->locations)){
    //  do what you will here
    foreach($locations_response->locations as $location){
        //  access location object
    }
}

Hope that helps!

huangapple
  • 本文由 发表于 2023年4月4日 15:48:34
  • 转载请务必保留本文链接:https://go.coder-hub.com/75926770.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定