【问题标题】:Google MyBusiness REST API update posts PATCH method request errorGoogle My Business REST API 更新发布 PATCH 方法请求错误
【发布时间】:2020-11-09 14:45:30
【问题描述】:

我想在 google my business 上更新特定帖子。我已经得到了account_idlocation_idpost_id。我正在使用 url https://mybusiness.googleapis.com/v4/{name=accounts/*/locations/*/localPosts/*} 并在我的后端执行 PATCH 方法。但是当我进行更新时,它会让我得到一个

 "code": 2,
 "field": "update_mask",
 "message": "update_mask is required"

我无法理解 Google 中的 update_mask 内容。有人能告诉我我应该怎么做吗?我正在使用 laravel btw 和 curl 库进行 http 请求。这是我的代码

    public function updatePost(Request $request ){
        $url = 'https://mybusiness.googleapis.com/v4/accounts/'.$request->account_id.'/locations/'.$request->location_id.'/localPosts/'.$request->post_id;
        $body['languageCode'] = "en-US";
        $body['summary'] = $request->summary;
        $body['callToAction'] = ['actionType'=> 'Call'];
        $body['media'][] = ['mediaFormat'=> 'PHOTO', "sourceUrl" => $request->imageURL];

        //Static Token only since for testing

        $headers = array(
            'Content-Type: application/json',
            'Accept: application/json',
            'Authorization: Bearer '.'ya29.a0AfH6SMB_1iUG11qj72p-pn_gCkOjUEf-ctvTGnJZ6FNTUy0Q3dYP54TMvI0cr8o0ditLp7CaWOUX5CTWn4v2kyQ-hZKSyuEJu_rBYX7uxvX373I9iVRxoypIZ6xhWDYTr-A_DHcaxGPVs1yz5u-fkYvU-xDppkASNbg'
        );

        $curl = curl_init();
        curl_setopt($curl, CURLOPT_URL, $url);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'PATCH');
        curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($body));
        curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
        $response = curl_exec($curl);

        dd($response);

    }

完整的消息

{
  "error": {
    "code": 400,
    "message": "Request contains an invalid argument.",
    "status": "INVALID_ARGUMENT",
    "details": [
      {
        "@type": "type.googleapis.com/google.mybusiness.v4.ValidationError",
        "errorDetails": [
          {
            "code": 2,
            "field": "update_mask",
            "message": "update_mask is required"
          }
        ]
      }
    ]
  }
}

补丁方法的文档 https://developers.google.com/my-business/reference/rest/v4/accounts.locations.localPosts/patch

【问题讨论】:

    标签: php laravel google-api httprequest google-api-php-client


    【解决方案1】:

    您需要将查询参数“updatemask”设置为要更新的字段。详情请查看this doc

    【讨论】:

      【解决方案2】:

      您需要为 upateMask 设置查询参数,如下所示。

      https://mybusiness.googleapis.com/v4/accounts/2323232334343/locations/232323232/localPosts/23232323232?updateMask=summary
      

      但是,我无法编辑其他字段,例如标题。

      你找到编辑其他的方法了吗?

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-08-05
        • 1970-01-01
        • 1970-01-01
        • 2015-09-11
        • 1970-01-01
        • 2020-02-16
        相关资源
        最近更新 更多