Search code examples
google-mapsgoogle-places-apirate-limiting

Paging on Google Places API returns status INVALID_REQUEST


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.


Solution

  • It is documented, see the documentation

    By default, each Nearby Search or Text Search returns up to 20 establishment results per query; however, each search can return as many as 60 results, split across three pages. If your search will return more than 20, then the search response will include an additional value — next_page_token. Pass the value of the next_page_token to the pagetoken parameter of a new search to see the next set of results. If the next_page_token is null, or is not returned, then there are no further results. There is a short delay between when a next_page_token is issued, and when it will become valid. Requesting the next page before it is available will return an INVALID_REQUEST response. Retrying the request with the same next_page_token will return the next page of results.