<?php
namespace App\Services;
use Google\Client;
use Google\Service\AndroidPublisher;
use Illuminate\Support\Facades\Log;
class GooglePlayReviewService
{
protected $androidPublisherService;
public function __construct()
{
$this->initializeGoogleClient();
}
protected function initializeGoogleClient()
{
$client = new Client();
$client->setAuthConfig(env('GOOGLE_APPLICATION_CREDENTIALS'));
$client->addScope(AndroidPublisher::ANDROIDPUBLISHER);
$this->androidPublisherService = new AndroidPublisher($client);
}
public function getReviews(string $packageName, int $maxResults = 100, ?string $token = null): array
{
try {
$params = [
'maxResults' => $maxResults,
];
if ($token) {
$params['token'] = $token;
}
$response = $this->androidPublisherService->reviews->listReviews($packageName, $params);
return [
'reviews' => $response->getReviews(),
'nextToken' => $response->getTokenPagination()?->getNextPageToken(),
];
} catch (\Exception $e) {
Log::error('Failed to fetch reviews: ' . $e->getMessage());
return [
'error' => $e->getMessage(),
];
}
}
}
<?php
namespace App\Http\Controllers;
use App\Services\GooglePlayReviewService;
use Illuminate\Http\Request;
class ReviewsController extends Controller
{
protected $googlePlayReviewsService;
public function __construct(GooglePlayReviewService $googlePlayReviewsService)
{
$this->googlePlayReviewsService = $googlePlayReviewsService;
}
public function fetchReviews(Request $request)
{
$packageName = "com.test.app";
$maxResults = "100";
$result = $this->googlePlayReviewsService->getReviews($packageName, $maxResults);
return response()->json($result);
}
}
I am encountering an issue with the Google Play Developer API (v3) when fetching reviews for an app. Despite setting
maxResultsto 100 or 50, thenextTokenin the response is consistentlynull, even when the number of reviews returned is less thanmaxResults, and I know additional reviews exist.Steps to Reproduce
Environment:
env('GOOGLE_APPLICATION_CREDENTIALS')(service account JSON)Code:
Service:
Controller:
API Request:
Example of the API request using the provided code:
Example API Response:
{ "reviews": [ { "authorName": "John Doe", "reviewId": "example-review-id", "comments": [ { "userComment": { "starRating": 5, "text": "Great app!", "lastModified": { "seconds": "1734128646" } } } ] } ], "nextToken": null }Expected Behavior
The
nextTokenfield in the API response should contain a value to indicate there are more reviews to fetch when the total number of reviews exceeds themaxResultsparameter.Observed Behavior
nextTokenfield isnullin the response, even when:maxResultsparameter (e.g., 80 reviews whenmaxResultsis 100).Additional Notes
env('GOOGLE_APPLICATION_CREDENTIALS'), and other API endpoints work as expected.maxResultsvalue (tested with 100 and 50).Environment
google/apiclient: ^2.18env('GOOGLE_APPLICATION_CREDENTIALS'))Request for Clarification
Could you confirm if:
nextToken?