Foursquare 场地 API 和结果数量,以更有效的方式?

发布于 2024-12-21 06:04:00 字数 708 浏览 1 评论 0原文

我想问除了这些选项之外,还有没有更有效的方法可以得到50个以上的结果?

我正在使用当前的 foursquare api 进行场地搜索 https://developer.foursquare.com/docs/venues/search

我想要的是类似偏移选项的东西,以便获得更多结果,但似乎没有这样的选项。

有替代解决方案吗? 先感谢您。

I'd like to ask if there is a more efficient way to get more than 50 results besides these options?

I'm using the current foursquare api for the venue search https://developer.foursquare.com/docs/venues/search .

What I'd like is something like an offset option, in order to get more results, but it seems that there isn't such an option.

Is there an alternative solution?
Thank you in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

瑕疵 2024-12-28 06:04:00

you should use venues explore with offset and limit as paramters,
venues explore gives you totalResults and you can use this response to calculate number of pages you need in paginate

for example assume totalResults is 90(pay attention at offset and limit parametr value )
in first request:
https://api.foursquare.com/v2/venues/explore?client_id=client_id&client_secret=client_secret&v=20150825&near=city_name&categoryId=category_id&intent=browse&offset=0&limit=30

in second request:
https://api.foursquare.com/v2/venues/explore?client_id=client_id&client_secret=client_secret&v=20150825&near=city_name&categoryId=category_id&intent=browse&offset=30&limit=30

in third request:
https://api.foursquare.com/v2/venues/explore?client_id=client_id&client_secret=client_secret&v=20150825&near=city_name&categoryId=category_id&intent=browse&offset=60&limit=30

for 90 results you can get all records with above three request

栩栩如生 2024-12-28 06:04:00

实际上这里没有提到另一个选项(虽然不是分页)

使用(实验性的?)categoryId 过滤器。

您可以使用不同的类别 ID 多次搜索单个点 (ll),从而获得许多结果(由于场地可能有多个类别,因此会出现一些重复结果)。

因此,您可以在同一地点搜索“美食”场所和“夜生活”场所,在 50 个结果中获得 100 个结果。正如所说,这是 100 个结果,但不是唯一的结果,可能会重复。我认为这比尝试使用浏览半径更有效。

不是分页,但会比普通搜索提供更多结果 - 即使在城市地区通常也足够了。

但是,是的,通过某种方式在单个点上提取超过 50 个数据是不可能的,但可能会很好:)

There is actually another option not mentioned here (not pagination though)

Using the (experimental?) categoryId filter.

You can search for a single point (ll) a few times with different category ids, giving you many results (some duplicates as venues can have more than one category).

So you can search for 'Food' venues and 'Nightlife' venues at the same place, getting 100 results in stand of 50.. as said it is 100 results, but not unique results, could be duplicates. I think that is more efficient then trying to play around with the browse radius thing.

Not pagination, but will give a lot more results than a normal search - usually enough even in urban areas.

But yea, having some sort of way to extract more than 50 on a single point is not possible, but could be nice :)

用心笑 2024-12-28 06:04:00

恐怕不是。目前没有分页,为了找到更多场地,您需要像突出显示的答案一样移动搜索区域。我同意,不过分页会很方便!

Afraid not. Currently there is no pagination, in order to find more venues you need to move your search area around as in the answers you highlighted. I agree, pagination would be handy though!

胡大本事 2024-12-28 06:04:00

对于资源管理器端点,这对我有用:例如,如果返回的最大结果数是 100,则只需在下一次调用中使用 offset=100,这会为您提供从 100(偏移量)开始的下 100 个结果。迭代(例如使用 while 循环)并不断将偏移量增加 100,直到达到总数或结果(在 api 中返回totalResults)。
我的第一篇堆栈溢出帖子,试图尽可能清楚地回答

For the explorer endpoint this worked for me: If the maximum number of results that is returned for instance is 100, just use offset=100 in the next call which gives you the next 100 results starting from 100 (the offset). Iterate (e.g. using while loop) and keep increasing offset by 100 until you reach the total number or results (which is returned in in the api for totalResults).
My first stack overflow post, tried to answer as clearly as possible

躲猫猫 2024-12-28 06:04:00
def getNearbyVenues(neighborhoods, latitudes, longitudes, radius=500,ven_num=300):
 
    venues_list=[]
    for name, lat, lng in zip(neighborhoods, latitudes, longitudes):
        i=0
        while (i < ven_num+50):
            
        
            url = 'https://api.foursquare.com/v2/venues/explore?&client_id={}&client_secret={}&v={}&ll={},{}&radius={}&offset={}&limit={}'.format(
            CLIENT_ID, 
            CLIENT_SECRET, 
            VERSION, 
            lat, 
            lng, 
            radius,
            i,
            LIMIT)
            
        # make the GET request
            results = requests.get(url).json()['response']['groups'][0]['items']
        
        # return only relevant information for each nearby venue
            venues_list.append([(
            name, 
            lat, 
            lng, 
            v['venue']['name'], 
            v['venue']['location']['lat'], 
            v['venue']['location']['lng'],  
            v['venue']['categories'][0]['name']) for v in results])
            i=i+50
            

    nearby_venues = pd.DataFrame([item for venue_list in venues_list for item in venue_list])
    nearby_venues.columns = ['Neighborhood', 
                  'Neighborhood Latitude', 
                  'Neighborhood Longitude', 
                  'Venue', 
                  'Venue Latitude', 
                  'Venue Longitude', 
                  'Venue Category']
    print('Ok')
    return(nearby_venues)

上面的代码非常适合我,其中 ven_num 变量是呼叫某个社区的场所所需的限制

def getNearbyVenues(neighborhoods, latitudes, longitudes, radius=500,ven_num=300):
 
    venues_list=[]
    for name, lat, lng in zip(neighborhoods, latitudes, longitudes):
        i=0
        while (i < ven_num+50):
            
        
            url = 'https://api.foursquare.com/v2/venues/explore?&client_id={}&client_secret={}&v={}&ll={},{}&radius={}&offset={}&limit={}'.format(
            CLIENT_ID, 
            CLIENT_SECRET, 
            VERSION, 
            lat, 
            lng, 
            radius,
            i,
            LIMIT)
            
        # make the GET request
            results = requests.get(url).json()['response']['groups'][0]['items']
        
        # return only relevant information for each nearby venue
            venues_list.append([(
            name, 
            lat, 
            lng, 
            v['venue']['name'], 
            v['venue']['location']['lat'], 
            v['venue']['location']['lng'],  
            v['venue']['categories'][0]['name']) for v in results])
            i=i+50
            

    nearby_venues = pd.DataFrame([item for venue_list in venues_list for item in venue_list])
    nearby_venues.columns = ['Neighborhood', 
                  'Neighborhood Latitude', 
                  'Neighborhood Longitude', 
                  'Venue', 
                  'Venue Latitude', 
                  'Venue Longitude', 
                  'Venue Category']
    print('Ok')
    return(nearby_venues)

the code above has worked perfectly with me, where ven_num variable is the desired limit for calling venues in a certain neighborhood

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文