微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何使用GMB API发布媒体?

如何解决如何使用GMB API发布媒体?

我正在尝试使用GMB API将媒体上传到我的GMB帐户。

我已经按照Goolge提供的库进行了安装。

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

Google支持人员说我们应该使用account.locations.media/create来上传媒体。

所以,我编写了以下源代码

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

一个参数还可以。 但是,第二个参数$mediaItem应该是Google_Service_MyBusiness_MediaItem。

因此,我正在寻找Google_Service_MyBusiness_MediaItem,看来我们无法使用此API发布媒体。

如何使用API​​将媒体上传到GMB?

对此我有点困惑。

最诚挚的问候,

解决方法

我找到了答案。 我们必须上传可以访问它的媒体。 我们无法将媒体直接上传到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);

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。