I have created app in foursquare and get the client_id and client_secret key . I need all the restaurants details of a city.but i got only 50 restaurant details. Please help me . thanks in advance
'https://api.foursquare.com/v2/venues/explore?near=San Francisco,San Francisco§ion=food&novelty=50&client_id=client_id&client_secret=client_secret&v=20170109';
Matt is correct that you can use the offset
parameter but his linked documentation and sample url was a little off.
It looks like you're using the venues/explore endpoint, you can find documentation on this here: https://developer.foursquare.com/docs/venues/explore
To page through results you would set up something like this:
https://api.foursquare.com/v2/venues/explore?client_secret=****&client_id=****&v=20161101&limit=50&near=San Francisco, CA§ion=food
In your response (json) you should inspect the json['response']['totalResults']
value to see how many results there are in total.
for (var i = 0; i < totalResults/50; i++) {
url = 'https://api.foursquare.com/v2/venues/explore?client_secret=****&client_id=****&v=20161101&limit=50&near=San Francisco, CA§ion=food&offset='(i + 1)*50';
}
It also looks like some of the parameters that you're using are invalid.
- The near parameter should be
San Francisco, CA
not San Francisco, San Francisco
- There is no
novelty
parameter with that API, do you mean to use limit
?
You should use the offset
parameter in order to page through the venues:
Here is the API docs:
https://developer.foursquare.com/docs/venues/listed
The stated limit is 200 so the example below will return a list of results 201-400:
https://api.foursquare.com/v2/venues/?limt=200&offset=201
for (var i = 0; i < numberOfPages; i++) {
url = 'https://api.foursquare.com/v2/venues/?limt=200&offset=' + i * 200;
}