当我尝试在 GMB API 中发布位置图像时收到此响应。
For media category of ADDITIONAL, LOGO, COVER it save successfully.But when another Category is selected got this response in return. 根据文档,类别选项如下。
封面、简介、徽标、外部、内部、产品、AT_WORK、食物和饮料、菜单、公共区域、房间、团队、附加
这是我的代码
/**
* Edit Media for Location
* @param Acconunt ID | Int
* @param Request | mixed
* @return JSON
*/
public function createMedia($id, $request)
{
$location = $request->get('loc_id');
if($this->checkAccess($id)){
if($this->googleClient->getAccessToken()){
$gmb = new GoogleMyBusiness($this->googleClient);
try {
foreach ($request->get('file_list') as $media) {
$data['category'] = $request->get('category');
$data['media_format'] = $media['mediaFormat'];
$data['source_url'] = $media['sourceUrl'];
$media_body = $this->createMediaBodyfromArray($data);
$post = $gmb->accounts_locations_media->create($location,$media_body);
}
return response()->json(['message' => 'Media created Successfully!']);
} catch (Exception $e) {
return response()->json(['message' => 'Media not created Successfully!'],500);
}
return;
}else{
return response()->json(['message' => 'Couldn`t create Media'],500);
}
}
}
/**
* Make Nedia Object to add Media in Google Location
* @return Google_Service_MyBusiness_MediaItem
*/
public function createMediaBodyfromArray($data)
{
$media_body = new Google_Service_MyBusiness_MediaItem;
// Location Accosiation Object
$loc_acc = new Google_Service_MyBusiness_LocationAssociation;
$loc_acc->setCategory($data['category']);
$media_body->setLocationAssociation($loc_acc);
$media_body->setMediaFormat($data['media_format']);
$media_body->setSourceUrl($data['source_url']);
return $media_body;
}
请求 POST /v4/accounts/{aid}/locations/{lid}/media
returns:
{
"error": {
"code": 400,
"message": "Request contains an invalid argument.",
"status": "INVALID_ARGUMENT",
"details": [
{
"@type": "type.googleapis.com/google.mybusiness.v4.ValidationError",
"errorDetails": [
{
"code": 3,
"message": "Photo tag \'photos_at_work\' does not apply to this location",
"value": "photos_at_work"
}
]
}
]
}
}