Open
Description
I am encountering an issue with the Google Play Developer API (v3) when fetching reviews for an app. Despite setting maxResults
to 100 or 50, the nextToken
in the response is consistently null
, even when the number of reviews returned is less than maxResults
, and I know additional reviews exist.
Steps to Reproduce
-
Environment:
- PHP Version: 8.4.1
- Laravel Framework: 11.31
- Google API Client Library: ^2.18
- Google Play Developer API Version: v3
- Authentication via
env('GOOGLE_APPLICATION_CREDENTIALS')
(service account JSON)
-
Code:
Service:
<?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(), ]; } } }
Controller:
<?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); } }
-
API Request:
Example of the API request using the provided code:
$result = $googlePlayReviewsService->getReviews("com.test.app", 100);
-
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 nextToken
field in the API response should contain a value to indicate there are more reviews to fetch when the total number of reviews exceeds the maxResults
parameter.
Observed Behavior
- The
nextToken
field isnull
in the response, even when:- Fewer reviews are returned than the
maxResults
parameter (e.g., 80 reviews whenmaxResults
is 100). - Additional reviews are available for the app.
- Fewer reviews are returned than the
Additional Notes
- I’ve verified that my authentication setup is correct using
env('GOOGLE_APPLICATION_CREDENTIALS')
, and other API endpoints work as expected. - This behavior occurs consistently, regardless of the
maxResults
value (tested with 100 and 50).
Environment
- PHP: 8.4.1
- Laravel Framework: ^11.31
google/apiclient
: ^2.18- Google Play Developer API Version: v3
- Authentication: Service Account JSON (
env('GOOGLE_APPLICATION_CREDENTIALS')
)
Request for Clarification
Could you confirm if:
- This is a bug with the API's pagination mechanism?
- There’s a specific filter or limitation causing this behavior?
- Any workaround exists to ensure all reviews are fetched without relying on
nextToken
?
Metadata
Metadata
Assignees
Labels
No labels