I'm able to connect to Google My Business and make a call to return the account number, but I can't list the locations associated to the account, and in turn, can't retrieve the reviews.
require_once( '/functions/google-api-php-client/vendor/autoload.php' );
require_once( '/functions/mybusiness/MyBusiness.php' );
$client = new Google_Client();
if ( $credentials_file = checkServiceAccountCredentialsFile() ) {
// set the location manually
$client->setAuthConfig( $credentials_file );
} elseif ( getenv( 'GOOGLE_APPLICATION_CREDENTIALS' ) ) {
// use the application default credentials
$client->useApplicationDefaultCredentials();
} else {
echo missingServiceAccountDetailsWarning();
return;
}
$client->setApplicationName( "Cardall_Orthodontics_Reviews" );
$client->setScopes( [ 'https://www.googleapis.com/auth/plus.business.manage' ] );
$service = new Google_Service_Mybusiness( $client );
$accounts = $service->accounts;
$accountsList = $accounts->listAccounts()->getAccounts();
$account = $accountsList[0];
$locations = $service->accounts_locations;
$locationsList = $locations->listAccountsLocations( $account->name )->getLocations(); // This is where it's not returning the locations
$location = $locationsList[0];
$reviews = $service->accounts_locations_reviews;
$listReviewsResponse = $reviews->listAccountsLocationsReviews( $location->name );
$reviewsList = $listReviewsResponse->getReviews();
When I print $account->name, I can see accounts/000000000000000000000
(with my account ID) so I'm only assuming it's working up until that point, but I'm not sure why there wouldn't be any locations. I have one added in My Business account.
You must add to your query required param "readMask":
$locationsList = $locations
->listAccountsLocations(
$account->name,
['readMask' => ['name', 'title',]]
)
->getLocations();
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.