google-maps-services-js
google-maps-services-js copied to clipboard
Error 400 when trying to load next page
Getting an error 400 when specifying the "pagetoken" in PlacesNearbyRequest.
Environment details
- Specify the API at the beginning of the title: PlacesNearby
- OS type and version: Windows 10
- Library version and other environment information: 3.1.13
Steps to reproduce
- Create a nearby search request
- Create a second search request using the nextpagetoken from the first request
- (Optionally: wait one second using the setTimeout function)
Code example
async loopPages(currentResponse: ParsedPlaceResponse, location: Location): Promise<PlaceResult> {
return new Promise<PlaceResult>(async (resolve, reject) => {
let places = [];
if (currentResponse.nextPage !== undefined) {
console.log("NEXT PAGE. Token: " + currentResponse.nextPage);
try {
let placeRequest = await this.loadPlaces({
params: {
key: GooglePlaceProvider.GOOGLE_API_KEY,
pagetoken: currentResponse.nextPage,
location: location
}
}, location);
currentResponse.nextPage = placeRequest.nextPage;
places.push(...(await this.loopPages(currentResponse, location)));
} catch(e) {
console.log(e);
await setTimeout(async () => places.push(...(await this.loopPages(currentResponse, location))), 1000);
}
}
resolve(places);
});
}
Stack trace
Request failed with status code 400
- node_modules\@googlemaps\google-maps-services-js\node_modules\axios\lib\core\createError.js:15:17 in createError
- node_modules\@googlemaps\google-maps-services-js\node_modules\axios\lib\core\settle.js:16:9 in settle
* http://192.168.178.100:19001/node_modules%5Cexpo%5CAppEntry.bundle?platform=android&dev=true&minify=false&hot=false:172585:14 in <unknown>
- node_modules\react-native\node_modules\promise\setimmediate\core.js:37:13 in tryCallOne
- node_modules\react-native\node_modules\promise\setimmediate\core.js:123:24 in setImmediate$argument_0
- node_modules\react-native\Libraries\Core\Timers\JSTimers.js:130:14 in _callTimer
- node_modules\react-native\Libraries\Core\Timers\JSTimers.js:181:14 in _callImmediatesPass
- node_modules\react-native\Libraries\Core\Timers\JSTimers.js:441:30 in callImmediates
- node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:387:6 in __callImmediates
- node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:135:6 in __guard$argument_0
- node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:364:10 in __guard
- node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:134:4 in flushedQueue
* [native code]:null in flushedQueue
* [native code]:null in callFunctionReturnFlushedQueue
Following these steps will guarantee the quickest resolution possible.
Thanks!
Same problem, when entering failing GET request directly in the browser it works.
Adding a setTimeout() fixes the problem.
It would be interesting to have a better error message.
@julesbou I already tried it with a timeout, but I'm receiving the same error.
Any further information on this?
Based on this: https://issuetracker.google.com/issues/35826470?pli=1
This is because of design and it's expected. In my case, the wait time was 2 seconds.
As mentioned by @joseglego, this is working as intended.