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

list locations is empty

Visitor ✭ ✭ ✭
# 1
Visitor ✭ ✭ ✭

HI,

 

I'm trying to get all locations of my GMB, but result is empty :

 

array (size=0)
  empty

here is my code : 

 

require_once '../google-api-php-client-1-master/src/Google/autoload.php';
require_once '../google-api-php-client-1-master/src/Google/Service/Mybusiness.php';


$key = 'mybusiness-77ddf3228f42.json';
$data = json_decode(file_get_contents($key)); // here i decoded the json

if (isset($data->type) && $data->type == 'service_account') {

$cred = new Google_Auth_AssertionCredentials(
'mybusiness@mybusiness-150310.iam.gserviceaccount.com',
array('https://www.googleapis.com/auth/plus.business.manage'),
$data->private_key // here is the private key
);
}

$client = new Google_Client();
$client->setAssertionCredentials($cred);

try {
$client->getAuth()->refreshTokenWithAssertion();
}
catch (Exception $e)
{
$e->getMessage();
}


// Lists all accounts for the authenticated user.
$mybusinessService = new Google_Service_Mybusiness($client);

$account = $mybusinessService->accounts->listAccounts()->getAccounts();
print_r($account);
$account_name = $account[0]->name;
$location = $mybusinessService->accounts_locations->listAccountsLocations($account_name)->getLocations();
var_dump($location);

 

can you help me please?

 

Thanks.

1 Expert replyverified_user

Re: list locations is empty

Google Employee
# 2
Google Employee

Hi @Passion B,

 

Judging from the source code you provided, it seems that you are building a service account application and we suggest you please check out this Accepted Solution for setting up a service account application.

 

Thanks,

The Google My Business API team