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

Help for newbie: PHP API Access 101

[ Edited ]
N/A
# 1
N/A

I have experience with the Google Analytics Core Reporting and Management APIs using the client libraries.

For example, to list my GA management profiles I use something like this:

$client = $this->getService('Google_Client');
$client->setClientId($this->settings['google_client_id']['value']);
$client->setClientSecret($this->settings['google_client_secret']['value']);
$client->setRedirectUri($this->Registry->get('google_api_callback_url'));
$client->refreshToken($this->Registry->get('google_refresh_token'));

$analytics = new Google_Service_Analytics($client);
$list_views = $analytics->management_profiles->listManagementProfiles($google_account_id, $google_property_id);
print_r($list_views);

and I get a response.

However when I try to access the GoogleMyBusiness API like this:

$client = $this->getService('Google_Client');
$client->setClientId($this->settings['google_client_id']['value']);
$client->setClientSecret($this->settings['google_client_secret']['value']);
$client->setRedirectUri($this->Registry->get('google_api_callback_url'));
$client->refreshToken($this->Registry->get('google_refresh_token'));

$gmbService = new Google_Service_MyBusiness($client);
$accounts = $gmbService->accounts->listAccounts();
print_r($accounts);

I get no response.

I've been granted access to the GMB API and I'm able to sent requests in the OAuth 2.0 Playground and get "200 OK" responses. i.e.
https://mybusiness.googleapis.com/v3/accounts lets me see:

{
  "accounts": [
    {
      "state": {
        "status": "UNVERIFIED"
      }, 
      "type": "PERSONAL", 
      "name": "accounts/MY_ACCOUNT_ID"
    }
  ]
}

What am I doing wrong?!

1 Expert replyverified_user

Re: Help for newbie: PHP API Access 101

Google Employee
# 2
Google Employee

Hi,

 

Judging from the source code you provided in your post, I notice that you are missing a method when trying to get a list of accounts using the Google My Business API. Please checkout the code below and include getAccounts() method in your code to see if it fixes your issue:

  

$gmbService = new Google_Service_MyBusiness($client);
$accounts = $gmbService->accounts;
$accountsList = $accounts->listAccounts()->getAccounts();

Also please check out this Accepted Solution for help in setting up your account with the PHP client library.

 

Thanks,

Shalini, The Google My Business API team