Method not found. error when using Google my business API
I am getting 404 from accouts list function by using google api client.
I have already access token by using OAuth2.0. In addition to this, I already enable the Google My Business API via https://console.developers.google.com for OAuth 2.0.
■Here is environemnt
PHP 7.2.3
Ubuntu 18.04 LTS
google/apiclient ^2.5
The function I want to execute is as following. https://developers.google.com/my-business/reference/rest/v4/accounts/list
I install google client libray by using composer from following link. https://github.com/googleapis/google-api-php-client
Since google my business library is seprated, I use this program. https://developers.google.com/my-business/samples
The steps to produce 404 is...
$client = new \Google_Client();
$client->setApplicationName("post_dev"); // app name
$client->setApprovalPrompt('force');
$client->setAccessType('offline');
$client->setAccessToken($credential);
$client->addScope("https://www.googleapis.com/auth/business.manage");
$client->addScope("https://www.googleapis.com/auth/plus.business.manage");
$gmbService = new \Google_Service_MyBusiness($client);
$results = $gmbService->accounts->listAccounts();
The variable $credential has following values.
client_id
client_secret
access_token
expires_in
refresh_token
After executing program, I am getting 404 erros like follwoing.
Google_Service_Exception[
404
]: {
"error": {
"code": 404,
"message": "Method not found.",
"errors": [
{
"message": "Method not found.",
"domain": "global",
"reason": "notFound"
}
],
"status": "NOT_FOUND"
}
}
It happens because you are trying to interact with the Google My Business API using a non-whitelisted project.
I faced the same issue. In my case, I submitted my project for whitelisting to unlock Google My Business API library.
Then, a couple weeks after that I created a new project under the same Google Cloud Platform account, just to set a more appropriate name. HERE was the root of the issue!
Even if you see the GMB library enabled at the account level, it works only at the PROJECT level. That's why you are getting 404 errors.
So, I switched everything to my original project (Consent screen settings, Oauth clients, etc)... The same on my localhost application, developed with Laravel Lumen 7.
After these couple changes, everything worked fine!
NOTE: Google allows you to whitelist 1 project per account ONLY! If your project/application were approved by Google, USE IT! Instead creating new ones.