Reputation: 162
I try implemented Google Client for download all reviews of my business place.
But I still get this error:
{
"error": {
"code": 403,
"message": "Google My Business API has not been used in project number before or it is disabled. Enable it by visiting https://console.developers.google.com/apis/api/mybusiness.googleapis.com/overview?project=number then retry. If you enabled this API recently, wait a few minutes for the action to propagate to our systems and retry.",
"errors": [
{
"message": "Google My Business API has not been used in project number before or it is disabled. Enable it by visiting https://console.developers.google.com/apis/api/mybusiness.googleapis.com/overview?project=number then retry. If you enabled this API recently, wait a few minutes for the action to propagate to our systems and retry.",
"domain": "usageLimits",
"reason": "accessNotConfigured",
"extendedHelp": "https://console.developers.google.com"
}
],
"status": "PERMISSION_DENIED",
"details": [
{
"@type": "type.googleapis.com/google.rpc.Help",
"links": [
{
"description": "Google developers console API activation",
"url": "https://console.developers.google.com/apis/api/mybusiness.googleapis.com/overview?project=number"
}
]
},
{
"@type": "type.googleapis.com/google.rpc.ErrorInfo",
"reason": "SERVICE_DISABLED",
"domain": "googleapis.com",
"metadata": {
"service": "mybusiness.googleapis.com",
"consumer": "projects/number"
}
}
]
}
}
If I visit https://console.developers.google.com/apis/api/mybusiness.googleapis.com/overview?project=******* I get error
Failed to load.
There was an error while loading /apis/library/mybusiness.googleapis.com?project=****. Please try again.
My code:
public function renderDownloadGoogleReviews()
{
/**Create client**/
$client = $this->getClient();
/**MyBusiness**/
$myBusiness = new Google_Service_MyBusiness($client);
$accounts = $myBusiness->accounts;
$accountsList = $accounts->listAccounts()->getAccounts();
dump($accountsList);
die();
}
public function renderRedirectUri()
{
$client = new Google_Client();
$client->setApplicationName('**Project Name**');
$client->setScopes(['https://www.googleapis.com/auth/business.manage', 'https://www.googleapis.com/auth/plus.business.manage']);
$client->setAuthConfig(self::CREDENTIALS_PATH);
$client->setAccessType('offline');
$authCode = $this->getParameter('code');
$accessToken = $client->fetchAccessTokenWithAuthCode($authCode);
// Store the credentials to disk.
if (!file_exists(dirname(self::TOKEN_PATH))) {
if (!mkdir($concurrentDirectory = dirname(self::TOKEN_PATH), 0700, true) && !is_dir($concurrentDirectory)) {
throw new \RuntimeException(sprintf('Directory "%s" was not created', $concurrentDirectory));
}
}
file_put_contents(self::TOKEN_PATH, json_encode($accessToken));
printf("Credentials saved to %s\n", self::TOKEN_PATH);
}
private function getClient(): Client
{
$client = new Google_Client();
$client->setApplicationName('**ProjectName**');
$client->setScopes(['https://www.googleapis.com/auth/business.manage', 'https://www.googleapis.com/auth/plus.business.manage']);
$client->setAuthConfig(self::CREDENTIALS_PATH);
$client->setAccessType('offline');
if (file_exists(self::TOKEN_PATH)) {
$accessToken = json_decode(file_get_contents(self::TOKEN_PATH), true);
} else {
$authUrl = $client->createAuthUrl();
echo "<a href='$authUrl'>$authUrl</a>";
die();
}
$client->setAccessToken($accessToken);
if ($client->isAccessTokenExpired()) {
$client->fetchAccessTokenWithRefreshToken($client->getRefreshToken());
file_put_contents(self::CREDENTIALS_PATH, json_encode($client->getAccessToken()));
}
return $client;
}
In Google console I have added:
Please can you tell me where I made mistake?
Thanks you.
Upvotes: 2
Views: 3049
Reputation: 66
You need to request access to their Google MyBusiness API as stated in the following link:
https://developers.google.com/my-business/content/prereqs#request-access
Here is the link to the form: https://docs.google.com/forms/d/1XTQc-QEjsE7YrgstyJxbFDnwmhUhBFFvpNJBw3VzuuE/viewform
Upvotes: 1
Reputation: 1603
Reviews are currently only available through a 9th API that you have not enabled:
The Google My Business API v4.9.
Upvotes: 2