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

How to create Client Object?

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

Hi there,

 

I would like to know how to create Client object?

 

I'm trying to create the Client object like this:

 

 

$client = new Google_Client();
$client->setAuthConfig('client_secret.json');
$client->setAccessType("offline"); // offline access
$client->setIncludeGrantedScopes(true); // incremental auth
$client->addScope(Google_Service_Drive::DRIVE_METADATA_READONLY);
$client->setRedirectUri('http://' . $_SERVER['HTTP_HOST'] . '/gauth/response_handler');


After that, I am then trying to get accountList:

 

 

MyBusiness = new Google_Service_MyBusiness($client);
$accounts = $MyBusiness->accounts;

try {
$accountsList = $accounts->listAccounts()->getAccounts();
} catch (Exception $e) {
print "Caught exception: " . $e->getMessage() . "\n";
}


But I get an Error:

 

Caught exception: { 
"error": { 
"code": 401, 
"message": "Request is missing required authentication credential. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.", 
"errors": [ {
"message": "Request is missing required authentication credential. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.",
"domain": "global", 
"reason": "unauthorized" 
} ],
"status": "UNAUTHENTICATED" 
} 
}

 

I think there is something wrong with Client object. Any idea what the problem?

1 Expert replyverified_user

Re: How to create Client Object?

Google Employee
# 2
Google Employee

Hi @Peter W,

 

We’ve verified that your project has been approved and whitelisted to use the Google My Business API. The 401 Unauthorized error you experienced may be related to OAuth 2.0 Authorization using the OAuth 2.0 client ID.

 

Please follow the Make a simple HTTP request step thoroughly on the Get Started page of the website for more information on how to use the OAuth 2.0 Playground to experiment with the Google My Business API.

 

If you are continuing to experience the 401 Unauthorized error, please provide screenshots of the error and we will help you troubleshoot the issue further.

 

Thanks,

The Google My Business API team

How to create Client Object?

Visitor ✭ ✭ ✭
# 3
Visitor ✭ ✭ ✭

Thanks for the feedback, now I have another slight issue.

 

Sometimes I get this message says: "Request contains an invalid argument". It's happens when I fill a field with incorrect data (for example by incorrect phone format), but documentation doesn't say what format I need to use and error message doesn't include some description about it.

 

Any ideas on what formats need to be used for which fields?

 

Thanks

Re: How to create Client Object?

Google Employee
# 4
Google Employee

Hi @Peter W,

 

According to our Google My Business listing guidelines, the primary phone number should be:  

  • The best phone number customers can reach the business
  • can be mobile device or landline
  • cannot be a fax
  • must be valid in country the business is located in

For the address format, please checkout this article.

 

Thanks,

Shalini, The Google My Business API team

Experts in the Topic
Shalini S