How to create local post on google using PHP MyBusiness API?

本小妞迷上赌 提交于 2020-07-11 06:51:20

问题


I want to create local post on google using google's PHP My Business API V4.

Sample code is below

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

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

where $locname is string of accounts/locations id.

above code throws exception 'Request contains an invalid argument.'

I want to know that how to create post or post data using PHP api.

Any help would be appreciated.


回答1:


For brands that have more than ten locations are not allowed to post on GMB through the API. Pull the location and check this flag $location->getLocationState()->getIsLocalPostApiDisabled().

Posting on 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);


来源:https://stackoverflow.com/questions/47766904/how-to-create-local-post-on-google-using-php-mybusiness-api

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!