【问题标题】:How to get venues based on certain categories?如何根据特定类别获取场地?
【发布时间】:2020-07-14 11:55:01
【问题描述】:

应该是这样的

https://api.foursquare.com/v2/venues/search?ll=40.7484,-73.9857&categoryId=4d4b7105d754a06374d81259&radius=100&limit=5&client_id=X&client_secret=X&v=20200101

4d4b7105d754a06374d81259 是食品的categoryId

所以,我希望获得该类别的场地列表。

但我得到了各种场地。

样本-

{
"meta": {
"code": 200
"requestId": "5f0d9ac6a0a468438f4f1b11"
}
"notifications": [
{
"type": "notificationTray"
"item": {
"unreadCount": 0
}
}
]
"response": {
"venues": [
{
"id": "43695300f964a5208c291fe3"
"name": "Empire State Building"
"contact": {
"phone": "+12127363100"
"formattedPhone": "+1 212-736-3100"
"twitter": "empirestatebldg"
"instagram": "empirestatebldg"
"facebook": "153817204635459"
"facebookUsername": "empirestatebuilding"
"facebookName": "Empire State Building"
}
"location": {
"address": "350 5th Ave"
"crossStreet": "btwn 33rd & 34th St"
"lat": 40.7485995507123
"lng": -73.98580648682452
"distance": 23
"postalCode": "10118"
"cc": "US"
"neighborhood": "Midtown Manhattan, New York, NY"
"city": "New York"
"state": "NY"
"country": "United States"
"formattedAddress": [
"0": "350 5th Ave (btwn 33rd & 34th St)"
"1": "New York, NY 10118"
"2": "United States"
]
}
"categories": [
"0": {
"id": "4bf58dd8d48988d130941735"
"name": "Building"                          # SEE HERE, ITS A BUILDING
"pluralName": "Buildings"
"shortName": "Building"
"icon": {
"prefix": "https://ss3.4sqi.net/img/categories_v2/building/default_"
"suffix": ".png"
}
"primary": true
}
]
"verified": true
"stats": {
"tipCount": 1165
"usersCount": 140228
"checkinsCount": 202739
}
"url": "https://www.esbnyc.com"
"venueRatingBlacklisted": true
"beenHere": {
"lastCheckinExpiredAt": 0
}
"venuePage": {
"id": "64514349"
}
"storeId": ""
"hereNow": {
"count": 0
"summary": "Nobody here"
"groups": [
]
}
"referralId": "v-1594727371"
"venueChains": [
]
"hasPerk": false
}
{
"id": "4bcca12bb6c49c7422169491"
"name": "86th Floor Observation Deck"
"contact": {
"phone": "+12127363100"
"formattedPhone": "+1 212-736-3100"
}
"location": {
"address": "350 5th Ave"
"crossStreet": "btwn 33rd & 34th Sts"
"lat": 40.74844544481811
"lng": -73.98568124187432
"labeledLatLngs": [
"0": {
"label": "display"
"lat": 40.74844544481811
"lng": -73.98568124187432
}
]
"distance": 5
"postalCode": "10118"
"cc": "US"
"city": "New York"
"state": "NY"
"country": "United States"
"formattedAddress": [
"0": "350 5th Ave (btwn 33rd & 34th Sts)"
"1": "New York, NY 10118"
"2": "United States"
]
}
"categories": [
"0": {
"id": "4bf58dd8d48988d165941735"
"name": "Scenic Lookout"                 # LOOK HERE, IT'S SCENIC LOOKOUT
"pluralName": "Scenic Lookouts"
"shortName": "Scenic Lookout"
"icon": {
"prefix": "https://ss3.4sqi.net/img/categories_v2/parks_outdoors/sceniclookout_"
"suffix": ".png"
}
"primary": true
}
]
"verified": true
"stats": {
"tipCount": 241
"usersCount": 21820
"checkinsCount": 23730
}
"beenHere": {
"lastCheckinExpiredAt": 0
}
"venuePage": {
"id": "64514350"
}
"hereNow": {
"count": 0
"summary": "Nobody here"
"groups": [
]
}
"referralId": "v-1594727371"
"venueChains": [
]
"hasPerk": false
}
{
"id": "5af44f23bcbf7a002ce0a18a"
"name": "Workday"
"contact": {
}
"location": {
"address": "350 5th Ave"
"lat": 40.748333
"lng": -73.985577
"labeledLatLngs": [
"0": {
"label": "display"
"lat": 40.748333
"lng": -73.985577
}
]
"distance": 12
"postalCode": "10001"
"cc": "US"
"city": "New York"
"state": "NY"
"country": "United States"
"formattedAddress": [
"0": "350 5th Ave"
"1": "New York, NY 10001"
"2": "United States"
]
}
"categories": [
"0": {
"id": "4bf58dd8d48988d124941735"
"name": "Office"                             # IT'S AN OFFICE
"pluralName": "Offices"
"shortName": "Office"
"icon": {
"prefix": "https://ss3.4sqi.net/img/categories_v2/building/default_"
"suffix": ".png"
}
"primary": true
}
]
"verified": false
"stats": {
"tipCount": 0
"usersCount": 12
"checkinsCount": 69
}
"venueRatingBlacklisted": true
"beenHere": {
"lastCheckinExpiredAt": 0
}
"hereNow": {
"count": 0
"summary": "Nobody here"
"groups": [
]
}
"referralId": "v-1594727371"
"venueChains": [
]
"hasPerk": false
}
{
"id": "5820b92252addb0cc786c053"
"name": "Expedia - New York City Office"
"contact": {
}
"location": {
"address": "350 5th Ave"
"lat": 40.748452
"lng": -73.985595
"labeledLatLngs": [
"0": {
"label": "display"
"lat": 40.748452
"lng": -73.985595
}
]
"distance": 10
"postalCode": "10118"
"cc": "US"
"city": "New York"
"state": "NY"
"country": "United States"
"formattedAddress": [
"0": "350 5th Ave"
"1": "New York, NY 10118"
"2": "United States"
]
}
"categories": [
"0": {
"id": "4bf58dd8d48988d124941735"
"name": "Office"
"pluralName": "Offices"
"shortName": "Office"
"icon": {
"prefix": "https://ss3.4sqi.net/img/categories_v2/building/default_"
"suffix": ".png"
}
"primary": true
}
]
"verified": false
"stats": {
"tipCount": 0
"usersCount": 15
"checkinsCount": 52
}
"venueRatingBlacklisted": true
"beenHere": {
"lastCheckinExpiredAt": 0
}
"hereNow": {
"count": 0
"summary": "Nobody here"
"groups": [
]
}
"referralId": "v-1594727371"
"venueChains": [
]
"hasPerk": false
}
{
"id": "59a44ba0e97dfb37208faf41"
"name": "JCDecaux, NA"
"contact": {
}
"location": {
"address": "350 Fifth Avenue, 73rd floor"
"lat": 40.74847232935598
"lng": -73.98566846513467
"labeledLatLngs": [
"0": {
"label": "display"
"lat": 40.74847232935598
"lng": -73.98566846513467
}
]
"distance": 8
"postalCode": "10001"
"cc": "US"
"city": "New York"
"state": "NY"
"country": "United States"
"formattedAddress": [
"0": "350 Fifth Avenue, 73rd floor"
"1": "New York, NY 10001"
"2": "United States"
]
}
"categories": [
"0": {
"id": "4bf58dd8d48988d124941735"
"name": "Office"
"pluralName": "Offices"
"shortName": "Office"
"icon": {
"prefix": "https://ss3.4sqi.net/img/categories_v2/building/default_"
"suffix": ".png"
}
"primary": true
}
]
"verified": false
"stats": {
"tipCount": 0
"usersCount": 21
"checkinsCount": 452
}
"venueRatingBlacklisted": true
"beenHere": {
"lastCheckinExpiredAt": 0
}
"hereNow": {
"count": 0
"summary": "Nobody here"
"groups": [
]
}
"referralId": "v-1594727371"
"venueChains": [
]
"hasPerk": false
}
]
"confident": false
}
}

那么,我到底做错了什么?应该怎么做才能只让那些类别为食品或其某些子类别的场所做出响应?

【问题讨论】:

    标签: api get python-requests location foursquare


    【解决方案1】:

    您的参数错误。将categoryID 替换为categoryId

    https://api.foursquare.com/v2/venues/search?ll=40.7484,-73.9857&categoryID=4d4b7105d754a06374d81259&radius=100&limit=5&client_id=X&client_secret=X&v=20200101->

    https://api.foursquare.com/v2/venues/search?ll=40.7484,-73.9857&categoryId=4d4b7105d754a06374d81259&radius=100&limit=5&client_id=X&client_secret=X&v=20200101

    【讨论】:

    • 我的错。我将其传递为categoryId。我这里写错了。
    • 我从this 的帖子中读到,回复仅包含场地的主要类别。
    • 现在我得到一个完全空洞的回复-{'meta': {'code': 200, 'requestId': '5f0daba93638df69a20b22cf'}, 'response': {'venues': []}} 知道为什么吗?这是我的网址-https://api.foursquare.com/v2/venues/search?&client_id=X&client_secret=X&v=20200101&ll=34.3615935047,-118.21698181100001&categoryId=4d4b7105d754a06374d81259&radius=1000&limit=100 我得到的是response = requests.get(url).json()
    • radius=1000 太小。试试radius=10000
    • 我做到了。那完成了工作。但地点是洛杉矶县。为什么方圆10公里内只有4个“美食”类场所?这正常吗?谢谢。 @Kosuke Ogawa
    【解决方案2】:

    两件事:

    • 我读到 categoryId 应该排在其他任何位置之前。我不确定它是否相关,但它对我有用。
    • 原来网址的半径只有100m,建议大一点的半径,可能也会影响结果。

    对我来说,这个网址非常有效:

    https://api.foursquare.com/v2/venues/search?categoryId=4d4b7105d754a06374d81259&ll=40.7,-74&client_id=X&client_secret=X&v=20200101&radius=700&limit=20

    【讨论】:

    • 我不必使用 categoryId 作为 API 调用的第一个参数。是的,100m 太小了。我将半径设置为 10 公里。
    猜你喜欢
    • 2016-08-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-03-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多