I am trying to show my android app reviews with reviewer name, date, rating. But I have some problems with authentication. Using google cloud with OAuth 2.0 Client IDs.
I use google/apiclient with PHP composer
{
"name": "app/reviews",
"description": "A project to fetch Google Play Store reviews using PHP",
"require": {
"google/apiclient": "^2.15.0"
},
"autoload": {
"psr-4": {
"App\": "src/"
}
}
}
here’s
credentials.json
{
"web":{
"client_id":"******-********.apps.googleusercontent.com",
"project_id":"****-****-373117",
"auth_uri":"https://accounts.google.com/o/oauth2/auth",
"token_uri":"https://oauth2.googleapis.com/token",
"auth_provider_x509_cert_url":"https://www.googleapis.com/oauth2/v1/certs",
"client_secret":"GOCSPX-*******"
}
}
here’s PHP code to show reviews
<?php
require '/path/to/vendor/autoload.php';
use GoogleClient;
use GoogleServiceAndroidPublisher;
function getReviews($applicationName) {
$client = new Client();
$client->setApplicationName('Reviews Client');
$client->setAuthConfig('/path/to/credentials.json');
$client->addScope(AndroidPublisher::ANDROIDPUBLISHER);
$service = new AndroidPublisher($client);
try {
$reviews = $service->reviews->listReviews($applicationName);
return $reviews;
} catch (Exception $e) {
echo 'Error: ', $e->getMessage();
return null;
}
}
$applicationName = 'com.****.****';
$reviews = getReviews($applicationName);
if ($reviews) {
foreach ($reviews as $review) {
echo 'Rating: ' . $review->getStars() . '<br>';
echo 'Comment: ' . $review->getText() . '<br><br>';
}
}
?>
but I get this when run it!
I want to know what’s the problem? Why Authentication failed.
