Reputation: 461
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:
It returns the results with no problem. So it's ok.
Result link for the next 20 objects like this:
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
Reputation: 71
This worked for me:
var WAIT_TIME = 2000;
await new Promise(resolve => setTimeout(resolve, WAIT_TIME));
Upvotes: 0
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