I'm using the Google Place API for place search:
https://developers.google.com/places/documentation/search
After the first query of the api, I'm getting the next page by setting the pagetoken. If I wait 2 seconds between requests, it works, but I notice that if I make the next query right after the previous one, it returns the status INVALID_REQUEST.
Is this some kind of rate limiting? I don't see this anywhere in the documentation.
https://developers.google.com/places/usage
Since each request has 20 places, getting a list of 100 results will take over 10 seconds which is a long time for someone to wait using an app.
It is documented, see the documentation
Although I'm not 100% sure this is the cause, I will leave this answer here as it took me around 6 hours to figure this out and may help someone.
As pointed out by geocodezip in his answer, there is a slight delay between the next page token being returned and that page actually being available. So I didn't find any other way to fix it other than making use of some sort of
sleep
.But what I did find out is that every request after the first
INVALID_REQUEST
response were also giving anINVALID_REQUEST
response, no matter if I waited 1, 2 or 10 seconds.I suspect it has something to do with a cached response from Google's Part. The solution I found is to append a random incremental new parameter to the URL as to make it a "different" URL, therefore requesting a cacheless response.
The parameter I used was
request_count
and for every request made, I incremented it by 1.For illustration purpose, here's the Python POC code I used (do not copy-paste as this is just a POC snippet and won't work):
EDIT: Forgot to mention that the
GooglePlaces
object is from slimkrazy's Google API lib. Unfortunatelly I had to tweak the code of the actual lib to accept this newrequest_count
parameter.I had to replace the
nearby_search
method for this: