I am getting this response when I try to post location image in GMB API.
For media category of ADDITIONAL, LOGO, COVER it save successfully.But when another Category is selected got this response in return. Categories options are following according to documentation.
COVER, PROFILE, LOGO, EXTERIOR, INTERIOR, PRODUCT, AT_WORK, FOOD_AND_DRINK, MENU, COMMON_AREA, ROOMS, TEAMS, ADDITIONAL
Here is my code
/**
* 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;
}
request to 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"
}
]
}
]
}
}