[Google Maps Places API] - Text Search missing next_page_token in response
- 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
]
*/
can confirm this is a huge issue
I can confirm this too, "nextPageToken" is never included.
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.
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 :(
Also having this issue. I'm sure it was working previously but no longer...
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:
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"
}
]
}
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?"
Unfortunately it is not working even with the older endpoint for me. I tried it but no token is returned in both version.
Coming back to this thread - as it seems like I'm getting nextPageToken once again in my return as of today (31st Aug 2024)
I can confirm that the nextPageToken is in the api call, but it's still not showing with PlacesClient
This is still an issue today, client library does not return nextPageToken, but curl does.
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"
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
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.
Still an issue please increase the priority or use jules to fix this
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.
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...
This is also happening on the nodejs client package.
For now I’ll do a manual fetch request and do a type assertion 🤷