Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Google Play Reviews API returns nextToken as null despite additional reviews being available #2647

Open
bobanpeaksel opened this issue Dec 14, 2024 · 0 comments

Comments

@bobanpeaksel
Copy link

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

  1. 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)
  2. 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);
        }
    }
  3. API Request:

    Example of the API request using the provided code:

    $result = $googlePlayReviewsService->getReviews("com.test.app", 100);
  4. 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 is null in the response, even when:
    • Fewer reviews are returned than the maxResults parameter (e.g., 80 reviews when maxResults is 100).
    • Additional reviews are available for the app.

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:

  1. This is a bug with the API's pagination mechanism?
  2. There’s a specific filter or limitation causing this behavior?
  3. Any workaround exists to ensure all reviews are fetched without relying on nextToken?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant