Yelp - Search API - Examples
I'm having trouble, getting the examples from the yelp-api git repository
to work (JavaScript version). I'm running it through my localhost via
wamp. I can log the queried data to the console, but I cannot get the data
to append or render into the selected div. Please take a look at the code
I am using and let me know what I am doing wrong. Thanks!!!
FYI - I used my OAuth keys in place of the placeholders seen below:
Yelp OAuth Example
var auth = { // // Update with your auth tokens // consumerKey:
"YOUR_CONSUMER_KEY", consumerSecret: "YOUR_CONSUMER_SECRET", accessToken:
"YOUR_TOKEN", // This example is a proof of concept, for how to use the
Yelp v2 API with javascript. // You wouldn't actually want to expose your
access token secret like this in a real application. accessTokenSecret:
"YOUR_TOKEN_SECRET", serviceProvider: { signatureMethod: "HMAC-SHA1" } };
var accessor = { consumerSecret: auth.consumerSecret, tokenSecret:
auth.accessTokenSecret }; parameters = []; parameters.push(['callback',
'cb']); parameters.push(['oauth_consumer_key', auth.consumerKey]);
parameters.push(['oauth_consumer_secret', auth.consumerSecret]);
parameters.push(['oauth_token', auth.accessToken]);
parameters.push(['oauth_signature_method', 'HMAC-SHA1']); var message = {
'action':
'http://api.yelp.com/v2/business/bay-to-breakers-12k-san-francisco',
'method': 'GET', 'parameters': parameters };
OAuth.setTimestampAndNonce(message); OAuth.SignatureMethod.sign(message,
accessor); var parameterMap = OAuth.getParameterMap(message.parameters);
parameterMap.oauth_signature =
OAuth.percentEncode(parameterMap.oauth_signature)
console.log(parameterMap); $.ajax({ 'url': message.action, 'data':
parameterMap, 'cache': true, 'dataType': 'jsonp', 'jsonpCallback': 'cb',
'success': function(data, textStats, XMLHttpRequest) { console.log(data);
$("body").append(data);
} });
No comments:
Post a Comment