【发布时间】:2020-11-09 14:45:30
【问题描述】:
我想在 google my business 上更新特定帖子。我已经得到了account_id、location_id 和post_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