0

its my first Google MyBusiness API encounter. Im trying to retrieve account locations but ive got nothing.

I dont have direct access for account, my client gave me access to API by json file.

$client = new Google_Client();
$client->useApplicationDefaultCredentials();
$client->addScope('https://www.googleapis.com/auth/plus.business.manage');

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

and i don't have any error, just Google_Service_MyBusiness_ListAccountsResponse object, then giving foreach on that object and I can get account informations:

object(Google_Service_MyBusiness_Account)[94]
  protected 'internal_gapi_mappings' => 
    array (size=0)
      empty
  public 'accountName' => null
  public 'accountNumber' => null
  public 'name' => string 'accounts/XXXXXXXXXXXXXXXXXXXXX' (length=30)
  protected 'organizationInfoType' => string 'Google_Service_MyBusiness_OrganizationInfo' (length=42)
  protected 'organizationInfoDataType' => string '' (length=0)
  public 'permissionLevel' => null
  public 'profilePhotoUrl' => string '.../photo.jpg' (length=94)
  public 'role' => null
  protected 'stateType' => string 'Google_Service_MyBusiness_AccountState' (length=38)
  protected 'stateDataType' => string '' (length=0)
  public 'type' => string 'PERSONAL' (length=8)
  protected 'modelData' => 
    array (size=0)
      empty
  protected 'processed' => 
    array (size=0)
      empty
  public 'state' => 
    object(Google_Service_MyBusiness_AccountState)[84]
      protected 'internal_gapi_mappings' => 
        array (size=0)
          empty
      public 'status' => string 'UNVERIFIED' (length=10)
      protected 'modelData' => 
        array (size=0)
          empty
      protected 'processed' => 
        array (size=0)
          empty

Now when i try:

$name = $account->getName(); //accounts/XXXXXXXXXXXXXXXXXXXXX
$service->accounts_locations->listAccountsLocations($name);

i get almost empty Google_Service_MyBusiness_ListLocationsResponse object:

object(Google_Service_MyBusiness_ListLocationsResponse)[88]
  protected 'collection_key' => string 'locations' (length=9)
  protected 'internal_gapi_mappings' => 
    array (size=0)
      empty
  protected 'locationsType' => string 'Google_Service_MyBusiness_Location' (length=34)
  protected 'locationsDataType' => string 'array' (length=5)
  public 'nextPageToken' => null
  public 'totalSize' => null
  protected 'modelData' => 
    array (size=0)
      empty
  protected 'processed' => 
    array (size=0)
      empty

What is wrong? Am I doing something wrong, or i have wrong credentials(?). How can I check/ask client that he gave me correct access. Can he check Account name in his panel or something?

Linda Lawton - DaImTo
  • 106,405
  • 32
  • 180
  • 449
unbreak
  • 1,000
  • 1
  • 16
  • 32
  • The .Json file is simply a client that has permission to access the API. That does not mean that it has access to any data. You need a user to login for that. which account did you login with? It apears that your account doesnt have access to any my business accounts. – Linda Lawton - DaImTo May 23 '19 at 12:26

1 Answers1

2

You appear to be trying to use a service account. As per the doucmentation Basic setup you need to create an Oauth2 client and use that to login to an account that has access to the my business account.

Service accounts do not appear to be supported by Google MyBusiness API as per the documentation.

Linda Lawton - DaImTo
  • 106,405
  • 32
  • 180
  • 449
  • Where did you found information that Service account are not supported by GMB API? – unbreak May 27 '19 at 09:58
  • If you check the [documentation](https://developers.google.com/my-business/content/basic-setup#request-client-id) you will notice that it mentions Oauth2. It does not mention service accounts this is because the way documentation works is we as developers document what we **do** support not what we dont. It would be to long to document everything thats not supported. – Linda Lawton - DaImTo May 27 '19 at 10:19
  • @DalmTo, thx. So why in json from my client i have oauth2 ulrs: ```{ "type": "service_account", "project_id": "", "private_key_id": "", "private_key": "private key", "client_email": "googleapi@XX-ZZ-YY.iam.gserviceaccount.com", "client_id": "123456789", "auth_uri": "https://accounts.google.com/o/oauth2/auth", "token_uri": "https://oauth2.googleapis.com/token", "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs", "client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/googleapi%40XX-ZZ-YY.iam.gserviceaccount.com" }``` – unbreak May 28 '19 at 12:31
  • thats just the token endpoint. its the same for all service account client it is up to you what API you use with it and not all of the apis support service account authentication. just tell them to make you an Oauth2 client and give you a user with access – Linda Lawton - DaImTo May 28 '19 at 19:09
  • Thanks, i need make some cron stuff without manual, javascript login, so I need service account :/ – unbreak May 28 '19 at 19:28
  • you can't use Oauth2 get a refresh token and use that to request a new access token. you are limited by what Google allows if they don't allow service accounts you can't use them – Linda Lawton - DaImTo May 28 '19 at 19:34