首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用GMB API发布媒体?

如何使用GMB API发布媒体?
EN

Stack Overflow用户
提问于 2020-08-21 16:16:53
回答 1查看 381关注 0票数 1

我正在尝试使用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

谷歌支持的人说我们应该使用accounts.locations.media/create来上传媒体。

所以,我写了下面的源代码。

代码语言:javascript
复制
$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将媒体上传到GMB?

我对此有点困惑。

诚挚的问候,

EN

回答 1

Stack Overflow用户

发布于 2020-08-21 17:50:31

我找到了答案。我们必须上传一个我们可以访问的媒体。我们不能直接将媒体上传到GMB API。

代码语言:javascript
复制
$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);
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/63519111

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档