Search code examples
javascriptjqueryapiyelp

Yelp API display only one ID using jQuery


Problem

I am trying to display the reviews of a Restaurant using Yelps API. I copied Smashing Magazines version of implementing API from their jQuery ebook. The problem is that using this method there are two stores being queried because the previous owners had the same phone number. Yelp can use phone numbers to query reviews and ratings. I need only the currently open store's reviews to display. I want to do it by some how showing Yelp's node elemnt ID. Each store has a unique identifier according to Yelps API and uses node element ID. The ID of the store i want to solely display is ID="Y6D43boKItksYx_d-RQL4g"

The Code Looks Like:

function showData(data) {
$.each(data.businesses, function(i,business){
// extra loop
var bizContent = '<p><img src="' + business.rating_img_url + '" img=""/><br><a href="'+ business.url +'">'+ business.review_count + ' reviews from Yelp.com</a></p>';
$(bizContent).appendTo('#yelpAVG');

$.each(business.reviews, function(i,review){
var content = '<div class="comments-block"><p>Posted by <a href="'+review.user_url+'">' +review.user_name + ' </a> on ' + review.date + 'via <a href="'+review.url+'">Yelp.com</a>';
content += '<img src="' + review.user_photo_url + '" img=""/>';
content += '<p><img src="' + review.rating_img_url + '" img=""/><br>';
content += review.text_excerpt + '</p>';
content += '<p><a href="'+review.url + '">Read the full review</a><br>';
$(content).appendTo('#yelpReviews');
});
});
}
function writeScriptTag(path) {
var yelpScript=document.createElement('script');
yelpScript.type='text/javascript';
yelpScript.src=path;
$("body").append(yelpScript);
}
$(document).ready(function(){
// note the use of the "callback" parameter
writeScriptTag( "http://api.yelp.com/phone_search?"+
"&categories.name=cafe"+
"&phone="+"(408) 292-2070"+
"&ywsid=Iua-78eDnxy0DTqm8I4mDw"+
"&limit=1"+
"&callback=showData"); 
});

Im a little new to jQuery so I wouldn't know where to begin or what I should start with to display queried results that only have

`ID="Y6D43boKItksYx_d-RQL4g"` 
ShowOnly="id":"Y6D43boKItksYx_d-RQL4g" or something similar.

Thanks For Reading.


Solution

  • You can't with API vsersion 1. but With APIv2 you can query a specific business by id: http://www.yelp.com/developers/documentation/v2/business Some sample code to help you get started is available on github: https://github.com/Yelp/yelp-api/blob/master/v2/js/business.html