我一直在尝试在yelp融合中实现业务搜索。但我无法得到结果,我已经给出了类别以便过滤 代码:
function yelpSearchReuslt(latitude,longitude,radius,listOfResult){
const searchRequest = {
categories:"Restaurants",
latitude:latitude,
longitude:longitude,
radius:radius
};
const client = yelp.client(API_KEY);
client.search(searchRequest).then(response => {
const firstResult = response.jsonBody.businesses;
})
在o / p中我得到了Playground和公园等类别 O / P:
{
"id": "U2lT4qo4R80vsYKUFaBoCA",
"alias": "lost-hills-wonderful-park-lost-hills",
"name": "Lost Hills Wonderful Park",
"image_url": "https://s3-media1.fl.yelpcdn.com/bphoto/t5y8zHqDfx5mN2v7wtvUxw/o.jpg",
"is_closed": false,
"url": "https://www.yelp.com/biz/lost-hills-wonderful-park-lost-hills?adjust_creative=KOlGv8v3EO9ZpCUlYru9eg&utm_campaign=yelp_api_v3&utm_medium=api_v3_business_search&utm_source=KOlGv8v3EO9ZpCUlYru9eg",
"review_count": 10,
"categories": [
{
"alias": "playgrounds",
"title": "Playgrounds"
},
{
"alias": "parks",
"title": "Parks"
}
],
"rating": 4.5,
"coordinates": {
"latitude": 35.6164124330499,
"longitude": -119.689275188145
},
"transactions": [],
"location": {
"address1": "14688 Lost Hills Rd",
"address2": "",
"address3": "",
"city": "Lost Hills",
"zip_code": "93249",
"country": "US",
"state": "CA",
"display_address": [
"14688 Lost Hills Rd",
"Lost Hills, CA 93249"
]
},
"phone": "+16614482149",
"display_phone": "(661) 448-2149",
"distance": 13784.418058437912
}
答案 0 :(得分:2)
看起来你差不多了。您只需要使用“类别”的标识符,而不是基于documentation for the categories parameter的名称:
“指定搜索类别输入时,应使用括号中的值。”
在您的情况下,使用restaurants
而不是Restaurants
。在上面的代码中,将searchRequest
的定义更改为:
const searchRequest = {
categories:"restaurants",
latitude:latitude,
longitude:longitude,
radius:radius
};
希望有所帮助!
-Darrin
答案 1 :(得分:1)
function yelpSearchReuslt(latitude,longitude,radius,ResultCount){
var request = require("request");
var options =
{
method: 'GET',
url: YELP_URL+latitude+"&longitude="+longitude+"&term="+"Restaurants"+"&limit="+ResultCount+"",
headers:
{
authorization:API_KEY
},
body: '{}'
};
request(options, function (error, response, body){
if (error) {
res.status(400).json({MESSAGE:MESSAGE})
}
}
答案 2 :(得分:1)
您需要将类别更改为术语并编辑答案
function yelpSearchReuslt(latitude,longitude,radius,listOfResult){
const searchRequest = {
term:"Restaurants",
latitude:latitude,
longitude:longitude,
radius:radius
};
const client = yelp.client(API_KEY);
client.search(searchRequest).then(response => {
const firstResult = response.jsonBody.businesses;
})