I’m trying to implement fetching Google reviews for my business in Laravel using google/apiclient but I keep getting response code 403 Forbidden after my GET request.
$client = new GoogleClient();
$serviceAccountKeyFilePath = storage_path('key-json.json');
$client->setAuthConfig($serviceAccountKeyFilePath);
$client->addScope('https://www.googleapis.com/auth/business.manage');
$client->setRedirectUri('http://' . $_SERVER['HTTP_HOST'] . '/oauth2callback.php');
$accessToken = $client->fetchAccessTokenWithAssertion();
if (isset($accessToken['access_token'])) {
$client->setAccessToken($accessToken['access_token']);
} else {
return;
}
$clientID = 'my-client-id';
$placeID = 'my-place-id';
$httpClient = $client->authorize();
$url = 'https://mybusiness.googleapis.com/v4/accounts/' . $clientID . '/locations/' . $placeID . '/reviews';
$response = $httpClient->get($url, [
'headers' => [
'Authorization' => 'Bearer ' . $accessToken['access_token'],
'Accept' => 'application/json',
],
]);
dd($response);
I enabled these APIs in my account:
- My Business Account Management API
- My Business Business Information API
- My Business Place Actions API
- Places API
- Places API (New)
But still I keep getting this
GuzzleHttpPsr7Response {#1670 ▼
-reasonPhrase: "Forbidden"
-statusCode: 403
}
I’m kinda confused and I can’t see what I am missing here.