AdWords is now Google Ads. Our new name reflects the full range of advertising options we offer across Search, Display, YouTube, and more. Learn more

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


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

I'm using the PHP Library to perform an account listing, my account shows as PERSONAL and UNVERIFIED which causes other functions to not work.



$client = new Google_Client();

$client->setAuthConfig($path); //path is to the JSON file


$mybusinessService = new Google_Service_Mybusiness($client);

$accounts = $mybusinessService->accounts->listAccounts();


This is server-to-server without user interaction (i.e. cron job) so I created a service account and downloaded the private key as JSON (as recommended).  This is a business account which has been verified to use the Google My Business API so I'm confused as to why it's showing incorrectly.  Is there another step that I'm missing to make the request come from the master and not just the service account?


Any ideas what I'm doing wrong?  Dug through TONS of documentation but to no help.


My goal is to use other functions from the PHP library such as $mybusinessService->accounts_locations->listAccountsLocations($accountName, array("pageSize"=>100)); but I cannot proceed.


  array(1) {
    array(1) {
      array(3) {
        string(30) "accounts/11111111111111111111111"
        string(8) "PERSONAL"
        array(1) {
          string(10) "UNVERIFIED"


1 Expert replyverified_user

Re: Google_Service_Mybusiness_ListAccountsResponse

Google Employee
# 2
Google Employee

Hi @PC R,


The source code you provided is for using an OAuth 2.0 client ID and persisting the refresh token during OAuth 2.0 flow with the Google API Client Library for PHP and the PHP client library. Your service account public/private key as a JSON file doesn’t work with the sample code you provided. You should check out the correct function call for making an authorized API call using the public/private key JSON file with the the Google API Client Library for PHP here. The UNVERIFIED account status indicates that your particular account is not bulk verified.


Due to the complexities involved in using service accounts, we strongly recommend using the OAuth 2.0 installed application flow and persisting the refresh token. This way, your application will always be able to request a new access token when necessary. This process requires a user to manually authorize the application during the OAuth 2.0 installed applications flow only once.


If you need specific features of a service account, you have to request user consent requiring human interaction for each Google Account that you need to access the Google My Business data from and manually authorize your app during OAuth 2.0 flow at least once prior to authenticating with the public/private key pair in your service account application. You can request user consent using OAuth 2.0 installed applications flow, OAuth 2.0 web server applications flow or via 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 account for access to their Google My Business data. If the end users later want to revoke the application’s access to their Google My Business data, they can remove the authorized app from the Apps connected to your account page of their accounts. Learn more


Please check out this Accepted Solution for requesting user consent for a service account application with the PHP client library (Note that I use service account public/private key as a standard P12 file in my code snippet). You can find code snippets for both using an OAuth 2.0 client ID and persisting the refresh token, and using a service account, respectively with the Google API Client Library for PHP in this thread. Please check out this Accepted Solution for listing all paginated locations by including the pageSize and pageToken query parameters with the PHP client library.


In addition, since the PHP client library doesn’t currently support the display of detailed error messages, you should follow the Make a simple HTTP request step-by-step guide on the Google Developers site to learn how to use the OAuth 2.0 Playground for troubleshooting errors with detailed error messages when sending requests with data via the Google My Business API.





Visitor ✭ ✭ ✭
# 3
Visitor ✭ ✭ ✭

Got it solved by:

creating an OAuth web key (for use on the playground).  using the playground allowed the account to be trusted.


used the service account JSON file within PHP and then $client->setSubject("?!?!?!?") to do the impersonations.


this finally allowed the solution to work.


when I moved the code to a different server, it failed RGGGGGHHH!!!!!  Found out that it is a requirement (believe with Guzzle) that the php.ini (or date_default_timezone_set in code) is set to the timezone.  Without that it wouldn't work and gave no help - very frustrating.