如何使用PHP MyBusiness API在谷歌上创建本地帖子?

时间:2017-12-12 06:58:26

标签: php google-api google-my-business-api

我想使用谷歌的PHP My Business API V4在谷歌上创建本地帖子。

示例代码在

下面
$mybusinessService = new \Google_Service_MyBusiness($client);
$local = new \Google_Service_MyBusiness_LocalPost();

$path = $locname.'/localPosts';
$response = $mybusinessService->accounts_locations_localPosts->create($path,$local);

其中$ locname是帐户/位置ID的字符串。

以上代码抛出异常'请求包含无效参数。'

我想知道如何使用PHP api创建帖子或帖子数据。

任何帮助都将不胜感激。

1 个答案:

答案 0 :(得分:0)

对于拥有超过10个地点的品牌,不允许通过API在GMB上发布。拉出位置并检查此标记$location->getLocationState()->getIsLocalPostApiDisabled().

  

在GMB Ex。上发布

        $posts = $mybusinessService->accounts_locations_localPosts;

        $newPost = new Google_Service_MyBusiness_LocalPost();

        $newPost->setSummary("Order your Thanksgiving turkeys now!!);           
        $newPost->setLanguageCode("en-US");
        $calltoaction = new Google_Service_MyBusiness_CallToAction();

        $calltoaction->setActionType("ORDER");

        $calltoaction->setUrl("http://google.com/order_turkeys_here");

        $newPost->setCallToAction($calltoaction);

        $media = new Google_Service_MyBusiness_MediaItem();

        $media->setMediaFormat("PHOTO");
        $media->setSourceUrl(https://www.google.com/real-turkey-photo.jpg);

        $newPost->setMedia($media); 

        $listPostsResponse = $posts->create( $location_name, $newPost);