How to post media using GMB API?

Viewed 700

I am trying to upload media to my GMB account using GMB API.

I have following Goolge provided libraries and installed.

https://github.com/googleapis/google-api-php-client https://developers.google.com/my-business/samples/google-api-services-mybusiness-v4p6-php-rev-20200422-1.zip

People from Google support said we should use accounts.locations.media/create to upload media.

So, I made following source code.

$obj = new \Google_Service_MyBusiness($this->getClient())
$obj->accounts_locations_media->create("accounts/000000/locations/00000",$mediaItem);  

First parameter is okay. But, Second parameter $mediaItem should be Google_Service_MyBusiness_MediaItem.

So, I look for Google_Service_MyBusiness_MediaItem and it looks like we can not post media using this API.

How can we just upload media to GMB using API?

I am bit confusing about this.

Best regards,

1 Answers

I found the answer. We have to upload a media where we can access to it. We CANNOT upload media directly to GMB API.

$obj = new \Google_Service_MyBusiness($this->getClient('mybusiness'));
$media = new Google_Service_MyBusiness_MediaItem();
$media->setName('test');
$media->setSourceUrl('https://webdesign-trends.net/wp/wp-content/uploads/2019/01/the-best-free-stock-photo-sites-945x567.png');
$locationAssocition = new Google_Service_MyBusiness_LocationAssociation();                                                                                                                    
$locationAssocition->setCategory('CATEGORY_UNSPECIFIED');                                                                                                                                     
$media->setLocationAssociation($locationAssocition);                                                                                                                                          
$media->setMediaFormat("PHOTO");                                                                                                                                                              
$obj->accounts_locations_media->create($accountLocation,$media);
Related