My Business
1.7K members online now
1.7K members online now
For developers who are using the Google My Business API to manage locations
Guide Me
star_border
Reply

How to get ALL locations

[ Edited ]
Visitor ✭ ✭ ✭
# 1
Visitor ✭ ✭ ✭

Hi Guys,

 

Just need some help in simply receiving a json feed from my Google My Business locations. I have tried using the php client and Mybusiness class to no avail. I do not wish to edit any details simply want to integrate GMB with Wordpress by getting the json feed converting it to a CSV and uploading it to my store locator plugin in wordpress. Any assistance on this matter is deeply appreciated ! 

 

Bass

1 Expert replyverified_user

Re: How to get ALL locations

Google Employee
# 2
Google Employee

Hi Bass from @HSW Marketing H,

 

You can use the PHP client library to send a GET request via the Google My Business API to list all of the locations for the specified account. At that point, you can use the json_encode function and pass the returned Location objects as an argument to get the JSON representation of all locations, or you can use the fputcsv function and pass the returned Location objects as an argument to directly write the fields to a CSV file.

 

I suppose you have gotten through the OAuth 2.0 Authorization, then you can follow the example in the below code snippet for listing the locations for the specified account with the PHP client library:

/************************************************

 We are going to create the Google My Business API

 service, and query it.

************************************************/

$mybusinessService = new Google_Service_Mybusiness($client);

 

$accounts = $mybusinessService->accounts;

// Lists all accounts for the authenticated user.

try {

 $accountsList = $accounts->listAccounts()->getAccounts();

} catch (Exception $e) {

 print "Caught exception: " . $e->getMessage() . "\n";

}

 

$locations = $mybusinessService->accounts_locations;

 

// For testing purposes, selects the very first account in the accounts array

$account = $accountsList[0];

 

// Lists all of the locations for the specified account.

try {

 $locationsList = $locations->listAccountsLocations($account->name)->getLocations();

} catch (Exception $e) {

 print "Caught exception: " . $e->getMessage() . "\n";

}

 

I hope this helps.

 

Thanks, 

Terry

How to get ALL locations

Visitor ✭ ✭ ✭
# 3
Visitor ✭ ✭ ✭

hey where you find "$client"?