0

我想使用谷歌的 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 创建帖子或发布数据。

任何帮助,将不胜感激。

4

1 回答 1

3

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

在 GMB 前张贴。

        $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);
于 2018-05-08T22:05:56.777 回答