我正在尝试对 Yelp API ( https://www.yelp.com/developers/documentation/v2/search_api ) 进行请求调用。但是,我在尝试将两个 lat lng 坐标值传递给参数 cll 之一时遇到了问题。 cll 键需要两个 double 值(lat 和 lng)。我尝试使用逗号作为分隔符创建两个点的字符串连接。我还尝试使用decodeURI()和encodeURI()方法来更改逗号,但这也不起作用。我还尝试将值作为两点数组传递,但这不起作用:/
以下是我如何使用 OAUTH 传递参数来查询我的参数。
var parameters = [];
parameters.push(['term', term]);
parameters.push(['limit', limit]);
parameters.push(['cll', latlngString]);
// latlngString = (lat.toString() + " , " +lng.toString());
.....
var parameterMap = OAuth.getParameterMap(message.parameters);
有谁知道在发出 GET 请求时将两个值传递给一个键的正确方法是什么?
最佳答案
我认为(关键字)我已经明白了,这可能是我见过的最愚蠢/最烦人的事情之一。
记下你给我的地址
https://api.yelp.com/v2/search?callback=cb&term=food&limit=5&cll=33.1866159649979%2C-117.35905740908515&callback=cb
显然,您已经编辑了从 oAuth 等传递的 key 和其他信息。一些随机的事情是,您有两次 callback=cb
部分,虽然理论上它不会导致服务器端出现任何问题,但技术上正确。
最大的事情是您没有包含位置变量
我已将您的请求提交给 postman ,添加了我自己的凭据(并且不知道这些纬度和经度指向何处,只需插入离我最近的城市,旧金山),显然我的信息被剥夺了,这是我发送的请求。请注意,唯一的区别是我传递了一个位置变量。 (甚至使用 "、 "
和 ","
进行了测试,我仍然得到相同的响应,因此第一个建议并没有真正改变任何东西)
https://api.yelp.com/v2/search?term=food&limit=5&cll=33.1866159649979%2C-117.35905740908515&location=San%20Francisco
postman 回复如下:
{
"region": {
"span": {
"latitude_delta": 0.017412363835347833,
"longitude_delta": 0.02850394313139759
},
"center": {
"latitude": 37.78660181083425,
"longitude": -122.408286062213
}
},
"total": 13061,
"businesses": [{
"is_claimed": true,
"rating": 4.5,
"mobile_url": "https://m.yelp.com/biz/southern-comfort-kitchen-san-francisco?adjust_creative=0fHKR3k58xfH-pxKxYNQdw\u0026utm_campaign=yelp_api\u0026utm_medium=api_v2_search\u0026utm_source=0fHKR3k58xfH-pxKxYNQdw",
"rating_img_url": "https://s3-media2.fl.yelpcdn.com/assets/2/www/img/99493c12711e/ico/stars/v1/stars_4_half.png",
"review_count": 115,
"name": "Southern Comfort Kitchen",
"rating_img_url_small": "https://s3-media2.fl.yelpcdn.com/assets/2/www/img/a5221e66bc70/ico/stars/v1/stars_small_4_half.png",
"url": "https://www.yelp.com/biz/southern-comfort-kitchen-san-francisco?adjust_creative=0fHKR3k58xfH-pxKxYNQdw\u0026utm_campaign=yelp_api\u0026utm_medium=api_v2_search\u0026utm_source=0fHKR3k58xfH-pxKxYNQdw",
"categories": [["Food Trucks", "foodtrucks"], ["Cajun/Creole", "cajun"]],
"phone": "5105496155",
"snippet_text": "Heard about their amazing southern fried chicken sandwich from my coworkers. So when their truck came around I had to try it! \n\nThe southern fried chicken...",
"image_url": "https://s3-media1.fl.yelpcdn.com/bphoto/Zxsno5qdvyZvXuD7C1WC2Q/ms.jpg",
"snippet_image_url": "https://s3-media3.fl.yelpcdn.com/photo/yIuFnDaqwBmeRv_ihUcufw/ms.jpg",
"display_phone": "+1-510-549-6155",
"rating_img_url_large": "https://s3-media4.fl.yelpcdn.com/assets/2/www/img/9f83790ff7f6/ico/stars/v1/stars_large_4_half.png",
"id": "southern-comfort-kitchen-san-francisco",
"is_closed": false,
"location": {
"city": "San Francisco",
"display_address": ["Hayes Valley", "San Francisco, CA 94102"],
"geo_accuracy": 5.0,
"neighborhoods": ["Hayes Valley", "Civic Center"],
"postal_code": "94102",
"country_code": "US",
"address": [],
"coordinate": {
"latitude": 37.78291,
"longitude": -122.41352
},
"state_code": "CA"
}
}, {
"is_claimed": true,
"rating": 4.5,
"mobile_url": "https://m.yelp.com/biz/tacorea-san-francisco?adjust_creative=0fHKR3k58xfH-pxKxYNQdw\u0026utm_campaign=yelp_api\u0026utm_medium=api_v2_search\u0026utm_source=0fHKR3k58xfH-pxKxYNQdw",
"rating_img_url": "https://s3-media2.fl.yelpcdn.com/assets/2/www/img/99493c12711e/ico/stars/v1/stars_4_half.png",
"review_count": 366,
"name": "Tacorea",
"rating_img_url_small": "https://s3-media2.fl.yelpcdn.com/assets/2/www/img/a5221e66bc70/ico/stars/v1/stars_small_4_half.png",
"url": "https://www.yelp.com/biz/tacorea-san-francisco?adjust_creative=0fHKR3k58xfH-pxKxYNQdw\u0026utm_campaign=yelp_api\u0026utm_medium=api_v2_search\u0026utm_source=0fHKR3k58xfH-pxKxYNQdw",
"categories": [["Mexican", "mexican"], ["Korean", "korean"], ["Latin American", "latin"]],
"menu_date_updated": 1472899698,
"phone": "4158851325",
"snippet_text": "We were staying a week in SAN Francisco a few blocks from this place. As MN natives living in an area with amazing Mexican food we needed to experience the...",
"image_url": "https://s3-media1.fl.yelpcdn.com/bphoto/7sOn8_P7Hxb0ZkM55tz3mg/ms.jpg",
"snippet_image_url": "https://s3-media4.fl.yelpcdn.com/photo/S_KZiQ1wHkS0D469bXVDdA/ms.jpg",
"display_phone": "+1-415-885-1325",
"rating_img_url_large": "https://s3-media4.fl.yelpcdn.com/assets/2/www/img/9f83790ff7f6/ico/stars/v1/stars_large_4_half.png",
"menu_provider": "single_platform",
"id": "tacorea-san-francisco",
"is_closed": false,
"location": {
"cross_streets": "Taylor St \u0026 Mason St",
"city": "San Francisco",
"display_address": ["809 Bush St", "Union Square", "San Francisco, CA 94108"],
"geo_accuracy": 9.5,
"neighborhoods": ["Union Square", "Lower Nob Hill"],
"postal_code": "94108",
"country_code": "US",
"address": ["809 Bush St"],
"coordinate": {
"latitude": 37.789806,
"longitude": -122.410709
},
"state_code": "CA"
}
}, {
"is_claimed": true,
"rating": 4.5,
"mobile_url": "https://m.yelp.com/biz/hot-sauce-and-panko-san-francisco?adjust_creative=0fHKR3k58xfH-pxKxYNQdw\u0026utm_campaign=yelp_api\u0026utm_medium=api_v2_search\u0026utm_source=0fHKR3k58xfH-pxKxYNQdw",
"rating_img_url": "https://s3-media2.fl.yelpcdn.com/assets/2/www/img/99493c12711e/ico/stars/v1/stars_4_half.png",
"review_count": 783,
"name": "Hot Sauce and Panko",
"rating_img_url_small": "https://s3-media2.fl.yelpcdn.com/assets/2/www/img/a5221e66bc70/ico/stars/v1/stars_small_4_half.png",
"url": "https://www.yelp.com/biz/hot-sauce-and-panko-san-francisco?adjust_creative=0fHKR3k58xfH-pxKxYNQdw\u0026utm_campaign=yelp_api\u0026utm_medium=api_v2_search\u0026utm_source=0fHKR3k58xfH-pxKxYNQdw",
"categories": [["Chicken Wings", "chicken_wings"], ["Specialty Food", "gourmet"]],
"menu_date_updated": 1472730119,
"phone": "4153591908",
"snippet_text": "If I can give this place more than 5 stars, I WOULD! I LA LA LA LOVE HOT SAUCE AND PANKO! Coming here, I was not expecting much. In fact, when my friend...",
"image_url": "https://s3-media4.fl.yelpcdn.com/bphoto/vKQD4EF6xk7_ryHtgiTAJA/ms.jpg",
"snippet_image_url": "https://s3-media2.fl.yelpcdn.com/photo/nAggqOjIiqELwX2D_RRRag/ms.jpg",
"display_phone": "+1-415-359-1908",
"rating_img_url_large": "https://s3-media4.fl.yelpcdn.com/assets/2/www/img/9f83790ff7f6/ico/stars/v1/stars_large_4_half.png",
"menu_provider": "single_platform",
"id": "hot-sauce-and-panko-san-francisco",
"is_closed": false,
"location": {
"cross_streets": "Washington St \u0026 Jackson St",
"city": "San Francisco",
"display_address": ["1468 Hyde St", "Nob Hill", "San Francisco, CA 94109"],
"geo_accuracy": 9.5,
"neighborhoods": ["Nob Hill"],
"postal_code": "94109",
"country_code": "US",
"address": ["1468 Hyde St"],
"coordinate": {
"latitude": 37.7945165216685,
"longitude": -122.417876198887
},
"state_code": "CA"
}
}, {
"is_claimed": true,
"rating": 4.5,
"mobile_url": "https://m.yelp.com/biz/hrd-san-francisco-4?adjust_creative=0fHKR3k58xfH-pxKxYNQdw\u0026utm_campaign=yelp_api\u0026utm_medium=api_v2_search\u0026utm_source=0fHKR3k58xfH-pxKxYNQdw",
"rating_img_url": "https://s3-media2.fl.yelpcdn.com/assets/2/www/img/99493c12711e/ico/stars/v1/stars_4_half.png",
"review_count": 1951,
"name": "HRD",
"rating_img_url_small": "https://s3-media2.fl.yelpcdn.com/assets/2/www/img/a5221e66bc70/ico/stars/v1/stars_small_4_half.png",
"url": "https://www.yelp.com/biz/hrd-san-francisco-4?adjust_creative=0fHKR3k58xfH-pxKxYNQdw\u0026utm_campaign=yelp_api\u0026utm_medium=api_v2_search\u0026utm_source=0fHKR3k58xfH-pxKxYNQdw",
"categories": [["Asian Fusion", "asianfusion"], ["Latin American", "latin"], ["Middle Eastern", "mideastern"]],
"menu_date_updated": 1481879601,
"phone": "4155432355",
"snippet_text": "Korean Mexican fusion at its finest! I ordered the eggplant katsu in a po' boy and it was delicious (but that might be because I'm partial to eggplant)....",
"image_url": "https://s3-media1.fl.yelpcdn.com/bphoto/ImvLt9I8ACHwfYthZw8vVw/ms.jpg",
"snippet_image_url": "https://s3-media3.fl.yelpcdn.com/photo/LmU4LKuS7iq8kxxcI3lwDw/ms.jpg",
"display_phone": "+1-415-543-2355",
"rating_img_url_large": "https://s3-media4.fl.yelpcdn.com/assets/2/www/img/9f83790ff7f6/ico/stars/v1/stars_large_4_half.png",
"menu_provider": "eat24",
"id": "hrd-san-francisco-4",
"is_closed": false,
"location": {
"cross_streets": "Taber Aly \u0026 Park Ave",
"city": "San Francisco",
"display_address": ["521A 3rd St", "SoMa", "San Francisco, CA 94107"],
"geo_accuracy": 9.5,
"neighborhoods": ["SoMa"],
"postal_code": "94107",
"country_code": "US",
"address": ["521A 3rd St"],
"coordinate": {
"latitude": 37.7811065758548,
"longitude": -122.395329724426
},
"state_code": "CA"
}
}, {
"is_claimed": true,
"rating": 4.5,
"mobile_url": "https://m.yelp.com/biz/box-kitchen-san-francisco?adjust_creative=0fHKR3k58xfH-pxKxYNQdw\u0026utm_campaign=yelp_api\u0026utm_medium=api_v2_search\u0026utm_source=0fHKR3k58xfH-pxKxYNQdw",
"rating_img_url": "https://s3-media2.fl.yelpcdn.com/assets/2/www/img/99493c12711e/ico/stars/v1/stars_4_half.png",
"review_count": 431,
"name": "Box Kitchen",
"rating_img_url_small": "https://s3-media2.fl.yelpcdn.com/assets/2/www/img/a5221e66bc70/ico/stars/v1/stars_small_4_half.png",
"url": "https://www.yelp.com/biz/box-kitchen-san-francisco?adjust_creative=0fHKR3k58xfH-pxKxYNQdw\u0026utm_campaign=yelp_api\u0026utm_medium=api_v2_search\u0026utm_source=0fHKR3k58xfH-pxKxYNQdw",
"categories": [["Food Stands", "foodstands"], ["Burgers", "burgers"]],
"phone": "4155807170",
"snippet_text": "Pretty much what most folks have said on here. I love that you walk up to a door and order your food in an alley. Bottom line is that the food is...",
"image_url": "https://s3-media2.fl.yelpcdn.com/bphoto/RgSY7vrLUfwWRh0-KuUpKQ/ms.jpg",
"snippet_image_url": "https://s3-media2.fl.yelpcdn.com/photo/4KoZLFB1sEYvTd9baSa2lg/ms.jpg",
"display_phone": "+1-415-580-7170",
"rating_img_url_large": "https://s3-media4.fl.yelpcdn.com/assets/2/www/img/9f83790ff7f6/ico/stars/v1/stars_large_4_half.png",
"id": "box-kitchen-san-francisco",
"is_closed": false,
"location": {
"cross_streets": "5th St \u0026 Mary St",
"city": "San Francisco",
"display_address": ["431 Natoma St", "SoMa", "San Francisco, CA 94103"],
"geo_accuracy": 9.5,
"neighborhoods": ["SoMa"],
"postal_code": "94103",
"country_code": "US",
"address": ["431 Natoma St"],
"coordinate": {
"latitude": 37.7811510761365,
"longitude": -122.40636505138
},
"state_code": "CA"
}
}]
}
另外!我提出了相同的凭据请求(在查找了那些纬度/经度坐标之后),只是将位置更改为圣地亚哥。
关于javascript - 如何使用 JS 将两个值(lat lng)传递给 GET 请求的一个参数键?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41214252/