Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use Google MyBusiness API in php

I am using Google MyBsiness API for fetching all business reviews. But I am unable to familer with PHP syntax and GET, POST method use in MYBusiness.

After Oath here are code i am using to fetch review

$mybusinessService = new Google_Service_Mybusiness($client);
$accessToken = file_get_contents($credentialsPath);

$reviews = $mybusinessService->accounts_locations_reviews;
echo '<pre>';print_r($reviews->get('ArtechDev'));exit;

But i am getting error 404 (Fatal error: Uncaught exception 'Google_Service_Exception' with message)

I am sure that I don't know how to pass param and which things needed for it. I am logged in as account which having Location 'ArtechDev' also please let me know that where can i call

https://mybusiness.googleapis.com/v3/accounts/account_name/locations/location_name/reviews

Thanks

like image 322
Bhavesh Nariya Avatar asked Jan 25 '17 00:01

Bhavesh Nariya


1 Answers

I hope you had found the answer to your question a long time ago, anyway I'll leave this hoping help someone else.

/*$accounts previusly populate*/
/*(GMB - v4)*/
$credentials_f = "google_my_business_credentials_file.json";
$client = new Google_Client();
$client->setApplicationName($aplicattion_name);
$client->setDeveloperKey($developer_key);
$client->setAuthConfig($credentials_f);  
$client->setScopes("https://www.googleapis.com/auth/plus.business.manage");
$client->setSubject($accounts->email);   
$token = $client->refreshToken($accounts->refresh_token);
$client->authorize();

$locationName = "accounts/#######/locations/########";

$mybusinessService = new Google_Service_Mybusiness($client);

$reviews = $mybusinessService->accounts_locations_reviews;

do{
    $listReviewsResponse = $reviews->listAccountsLocationsReviews($locationName, array('pageSize' => 100,
                        'pageToken' => $listReviewsResponse->nextPageToken));

    $reviewsList = $listReviewsResponse->getReviews();
    foreach ($reviewsList as $index => $review) {
        /*Accesing $review Object

        * $review->createTime;
        * $review->updateTime;
        * $review->starRating;
        * $review->reviewer->displayName;
        * $review->reviewReply->comment;
        * $review->getReviewReply()->getComment();
        * $review->getReviewReply()->getUpdateTime();
        */

    }

}while($listReviewsResponse->nextPageToken);
like image 152
Angie Avatar answered Oct 09 '22 11:10

Angie