How to get all the venues data using foursquare api

橙三吉。 提交于 2019-12-12 03:44:22

问题


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&section=food&novelty=50&client_id=client_id&client_secret=client_secret&v=20170109';

回答1:


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&section=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&section=food&offset='(i + 1)*50';
}

It also looks like some of the parameters that you're using are invalid.

  1. The near parameter should be San Francisco, CA not San Francisco, San Francisco
  2. There is no novelty parameter with that API, do you mean to use limit?



回答2:


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;
}


来源:https://stackoverflow.com/questions/41571392/how-to-get-all-the-venues-data-using-foursquare-api

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!