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

SDK Can't access to my locations

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



I use Server to Server method to connect my Website to the API.


I can connect to the API with Google Client like this :



        $clientSecret = 'service_account.json';

        $client = new \Google_Client();


Then, I can connect to the service Google Service MyBusiness with the client like this : 



        $service = new \Google_Service_MyBusiness($client);

        $listAccounts  = $service->accounts->listAccounts();
        // Return the name of my account
        $nameOfAccount = $listAccounts[0]->name;
        $locations     = $service->accounts_locations->listAccountsLocations($nameOfAccount);


The point is that my locations are empties (I don't see the locations whose are presents in Google My Business).


In Google Console Developers, I can see the traffic of the API call (so I think, my connection to the API works, right?)


What can I do?


Thank by advance,

Gueudet Team

1 Expert replyverified_user

Re: SDK Can't access to my locations

Google Employee
# 2
Google Employee

Hi @Marketing R,


Since you are building a service account application, I suggest you please check out this Accepted Solution to make sure that you followed the required steps to setting up a service account application to work with the Google My Business API.


Please note, since the PHP client library doesn’t currently support the display of detailed error messages, so I suggest you follow the Make a simple HTTP request step-by-step guide on the Google Developers site and try use the OAuth 2.0 Playground to step through the auth flow, and examine the HTTP request/response at each step. This usually helps pinpoint where an application is passing the incorrect info.



Shalini, Google My Business API team

Re: SDK Can't access to my locations

Visitor ✭ ✭ ✭
# 3
Visitor ✭ ✭ ✭

Hi @Shalini S


Yes, I follow your solution but we have the same problem.


We are connected to the API (no errors), but we don't have any data of our Google My Business Account.


We don't understand how to connect Google My Business to Google Service Account.


Also, we used OAuth 2.0 Playground and of course it works, but in your application we used Server To Server method. 

So we have downloaded the credentials in .json (explicated in my last message).


When we call the API, we can see the list of accounts : 


Google_Service_MyBusiness_ListAccountsResponse {#620
  #collection_key: "accounts"
  #internal_gapi_mappings: []
  #accountsType: "Google_Service_MyBusiness_Account"
  #accountsDataType: "array"
  +nextPageToken: null
  #modelData: array:1 [
    "accounts" => array:1 [
      0 => array:3 [
        "name" => "accounts/109187562777120980118"
        "type" => "PERSONAL"
        "state" => array:1 [
          "status" => "UNVERIFIED"
  #processed: []



But, when we want to see the list of locations, we receive an empty list. 


What can we do?

Re: SDK Can't access to my locations

Google Employee
# 4
Google Employee

Hi @Marketing R,


For using a service account to access the Google My Business account and location data on behalf of a particular end user, you should request user consent for that end user’s Google Account only once. You can perform this process during the OAuth 2.0 installed application flow or using OAuth 2.0 Playground. When you prepare to make authorized API calls using the service account, you specify the user to impersonate by specifying the email address of the user’s Google Account for access to their Google My Business data.


Please check out this Accepted Solution for listing all paginated locations by including the pageSize and pageToken query parameters with the PHP client library.



The Google My Business API team