google-cloud-node icon indicating copy to clipboard operation
google-cloud-node copied to clipboard

[Google Maps Places API] - Text Search missing next_page_token in response

Open shaunmitchellve opened this issue 1 year ago • 19 comments

  • which product (packages/*): packages/google-maps-places
  • OS: OSX
  • Node.js version: 21.7.2
  • npm version: 10.6.0
  • google-cloud-node version:Place2 1.6.0

Steps to reproduce

  • npm i @googlemap/places
const {PlacesClient} = require('@googlemaps/places').v1;

 let response = await placesClient.searchText(textQuery: 'something', {
 otherArgs: {
  headers: {
   'x-Goog-FieldMask': 'places.displayName',  
},}});

console.log(response);

/*
response:
[
  {
    places: [
      [Object], [Object], [Object],
      [Object], [Object], [Object],
      [Object], [Object], [Object],
      [Object], [Object], [Object],
      [Object], [Object], [Object],
      [Object], [Object], [Object],
      [Object], [Object]
    ],
    contextualContents: []
  },
  null,
  null
]

I would expect something like:
[
  {
    places: [
      [Object], [Object], [Object],
      [Object], [Object], [Object],
      [Object], [Object], [Object],
      [Object], [Object], [Object],
      [Object], [Object], [Object],
      [Object], [Object], [Object],
      [Object], [Object]
    ],
    contextualContents: [],
    nextPageToken: ''
  },
  null,
  null
]
*/

shaunmitchellve avatar May 24 '24 20:05 shaunmitchellve

can confirm this is a huge issue

alturda avatar Jun 07 '24 15:06 alturda

I can confirm this too, "nextPageToken" is never included.

richardmarchant avatar Jul 17 '24 10:07 richardmarchant

see

Can you try setting autoPaginate: false or using the Async method?

sofisl avatar Jul 18 '24 16:07 sofisl

Adding in the autoPagination: false into the GAX options doesn't seem to work, unless I'm doing it wrong

import {PlacesClient} from '@googlemaps/places';

const placesClient = new PlacesClient();

const response = await placesClient.searchText(
{
    textQuery: 'something',
    pageSize: 10,
},
{
    autoPaginate: false,
    otherArgs: {
        headers: {
        'X-Goog-FieldMask': 'places.id,places.displayName',
        },
    },
});

console.log('Places: ', response);
// RESPONSE
Places:  [
  {
    places: [
      [Object], [Object], [Object],
      [Object], [Object], [Object],
      [Object], [Object], [Object],
      [Object], [Object], [Object],
      [Object], [Object], [Object],
      [Object], [Object], [Object],
      [Object], [Object]
    ],
    contextualContents: []
  },
  null,
  null
]
import {PlacesClient} from '@googlemaps/places';

const placesClient = new PlacesClient();

const [resultArray, nextPageRequest, rawRespone] = await placesClient.searchText(
{
    textQuery: 'schools in Calgary Alberta',
},
{
    autoPaginate: false,
    otherArgs: {
        headers: {
        'X-Goog-FieldMask': 'places.id,places.displayName',
        },
    },
});

console.log("RESULTS:", resultArray);
console.log("NEXT PAGE: ", nextPageRequest);
console.log("RAW: ", rawRespone);
 

//RESPONSE:
RESULTS: {Places:  [
  {
    places: [
      [Object], [Object], [Object],
      [Object], [Object], [Object],
      [Object], [Object], [Object],
      [Object], [Object], [Object],
      [Object], [Object], [Object],
      [Object], [Object], [Object],
      [Object], [Object]
    ],
    contextualContents: []
  }
]
}

NEXT PAGE:  null
RAW:  null

Also, there doesn't appear to be any searchTextAsync function definition so it errors out when attempting to use that approach.

shaunmitchellve avatar Jul 18 '24 19:07 shaunmitchellve

Yesterday it worked for me but today not. Also in the API Text on Google page, filled with the Demo from the page, the nextPageToken does not appear.

https://developers.google.com/maps/documentation/places/web-service/text-search?hl=en

The example from the page

 curl -X POST -d '{
  "textQuery": "pizza in New York",
  "pageSize": 5
  }' \
-H 'Content-Type: application/json' -H 'X-Goog-Api-Key: API_KEY' \
-H "X-Goog-FieldMask: places.id,nextPageToken" \
'https://places.googleapis.com/v1/places:searchText'

Makes it basically impossible to use this API :(

bscthartmann avatar Aug 27 '24 12:08 bscthartmann

Also having this issue. I'm sure it was working previously but no longer...

LombaxTech avatar Aug 27 '24 15:08 LombaxTech

I concur with @bscthartmann that this seems to be broken in the API itself. This curl request from the documentation does not return a token as specified:

Docs

Reality
❯  curl -X POST -d '{
  "textQuery": "pizza in New York",
  "pageSize": 5
  }' \
-H 'Content-Type: application/json' -H 'X-Goog-Api-Key:  [API_KEY] \
-H "X-Goog-FieldMask: places.id,nextPageToken" \
'https://places.googleapis.com/v1/places:searchText'
{
  "places": [
    {
      "id": "ChIJifIePKtZwokRVZ-UdRGkZzs"
    },
    {
      "id": "ChIJ6xvs94VZwokRnT1D2lX2OTw"
    },
    {
      "id": "ChIJqcgHCJ1ZwokRRmJ-uWL5DAA"
    },
    {
      "id": "ChIJjaD94kFZwokR-20CXqlpy_4"
    },
    {
      "id": "ChIJmcyIPBVZwokRq8rnnNYek0w"
    }
  ]
}

probablykabari avatar Aug 28 '24 05:08 probablykabari

I can confirm—everything was working fine for me until around Sunday, August 25, 2024. However, my web app is now broken because the nextPageToken is no longer being returned in the API calls. I'm using the new Places API text search request (endpoint starting with https://places.googleapis.com/v1/places:searchText). I'm considering rolling back to the previous version of the Places API (endpoint starting with https://maps.googleapis.com/maps/api/place/textsearch). Can anyone confirm if the nextPageToken is still working with the older endpoint?"

Hugh-Kane avatar Aug 28 '24 08:08 Hugh-Kane

Unfortunately it is not working even with the older endpoint for me. I tried it but no token is returned in both version.

LombaxTech avatar Aug 28 '24 14:08 LombaxTech

Coming back to this thread - as it seems like I'm getting nextPageToken once again in my return as of today (31st Aug 2024)

Hugh-Kane avatar Aug 31 '24 11:08 Hugh-Kane

I can confirm that the nextPageToken is in the api call, but it's still not showing with PlacesClient

acaumartin-cameleon avatar Sep 04 '24 13:09 acaumartin-cameleon

This is still an issue today, client library does not return nextPageToken, but curl does.

Ryguy10712 avatar Jan 24 '25 15:01 Ryguy10712

Noticed that the nextPageToken seems to appear with this "textQuery": "Spicy Vegetarian Food in Sydney, Australia" but not with hotels. e.g. "textQuery": "hotels in Sydney, Australia"

llaurenz avatar Jan 27 '25 17:01 llaurenz

As written on their documentation, you have to specify nextPageToken inside your X-Goog-FieldMask header.

Example : X-Goog-FieldMask: places.id,places.shortFormattedAddress,nextPageToken

Image

ThibaultClerc avatar Feb 27 '25 08:02 ThibaultClerc

Yes, you can request it but it's never returned from RPC client. Even if it's there in response it's not being mapped in the response so one never gets access to it. It forces one to write custom solutions.

EDIT: I'm talking about python library client.

furai avatar May 13 '25 12:05 furai

Still an issue please increase the priority or use jules to fix this

DomEscobar avatar Jun 11 '25 17:06 DomEscobar

Hi all, I can confirm this is still a bug in the @googlemaps/places client. The nextPageToken is not exposed in the response, making pagination impossible through the library.

The issue is definitely in the client, because making a direct POST request to the API endpoint works perfectly. As a workaround, you can bypass the client and use axios or any other HTTP client.

Here’s a simple example that proves the API provides the token correctly when asked:

     const axios = require('axios');
    
    const GOOGLE_API_KEY = 'YOUR_API_KEY';
    const API_URL = 'https://places.googleapis.com/v1/places:searchText';
     
    async function getNextPageToken() {
      try {
         const response = await axios.post(API_URL,
           // Request Body
          {
            textQuery: 'pizza in New York',
            pageSize: 5
          },
          // Request Headers
          {
            headers: {
              'Content-Type': 'application/json',
              'X-Goog-Api-Key': GOOGLE_API_KEY,
             // You MUST include 'nextPageToken' in the field mask
              'X-Goog-FieldMask': 'places.id,nextPageToken'
            }
          }
       );
    
     // This will correctly log the response with the nextPageToken
     console.log(response.data);
     // Example output: { places: [...], nextPageToken: '...' }
    
      } catch (error) {
        console.error('Error:', error.response ? error.response.data : error.message);
      }
    }
    
   getNextPageToken();

This workaround shows the API is behaving as expected. I hope the team can prioritize a fix for the @googlemaps/places client soon.

martino2197 avatar Aug 01 '25 20:08 martino2197

Can confirm the same happens with the .NET Cloud Client Library, the only workaround I can think about is writing a custom solution, which defeats the purpose of using a client library in the first place...

nyrzeff avatar Oct 08 '25 19:10 nyrzeff

This is also happening on the nodejs client package.

For now I’ll do a manual fetch request and do a type assertion 🤷

JWPapi avatar Nov 11 '25 17:11 JWPapi