Igor
Igor

Reputation: 461

Google place INVALID_REQUEST while sending request to get next page results

I've faced with problem in iOS application.

I have to get all 60 Google places. I created loop for sending request and parsing the results. In this loop I created URL like this:

if (nextPageToken != nil && ![nextPageToken isEqualToString:@""])
    pageToken = [NSString stringWithFormat:@"&pagetoken=%@", nextPageToken];

NSString *webStringURL = [[NSString stringWithFormat:@"%@?sensor=true&key=%@&location=%@&radius=%@%@", urlString, apiKey, location, radius, pageToken] stringByAddingPercentEscapesUsingEncoding:NSUTF32StringEncoding];

Result link for first 20 objects:

https://maps.googleapis.com/maps/api/place/search/json?sensor=true&key=YOUR_KEY4&location=50.907654,34.823147&radius=50000&language=ru

It returns the results with no problem. So it's ok.

Result link for the next 20 objects like this:

https://maps.googleapis.com/maps/api/place/search/json?sensor=true&key=YOUR_KEY&location=50.907654,34.823147&radius=50000&pagetoken=ClREAAAA0zIx19jIHXfj0d4vjuIzshv9FTRi9l-ULIAovq5B9Ls0W_vzQFtL6rHVLfoJW4ICpIJlIG3QNRdfayfWp-4L1EjxDklb_kLBquJWX4_jSkgSEMKa1VgBGNQD3jCzW12OrOwaFExWU5GvZXgmKilw8ecaNzMhrucW

But in this case application receives status "INVALID_REQUEST". If I open this link in browser everything is OK. Google returns me the results.

Could you help me what's wrong? I spent a lot of time but I couldn't figure out what I did wrong.

Thanks in advance.

P.S. Sorry for my poor English.

Upvotes: 2

Views: 2227

Answers (2)

Giovanni Pedretti
Giovanni Pedretti

Reputation: 71

This worked for me:

var WAIT_TIME = 2000;
await new Promise(resolve => setTimeout(resolve, WAIT_TIME));

Upvotes: 0

pushbit
pushbit

Reputation: 1268

https://developers.google.com/places/documentation/search#PlaceSearchPaging

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.

Try adding a one (or more) second delay between your requests.

Upvotes: 7

Related Questions