I am trying to call the Yelp API using AngularJS, but I am having problems. I keep getting 400 bad requests and I don’t know why.
Yelp API Documentation:
http://www.yelp.com/developers/documentation/v2/authentication http://www.yelp.com/developers/documentation/v2/search_api
Page containing the generated Yelp API keys:
http://gyazo.com/fa918329eb0cde18a5db242d1d0b0b0e
This is the code snippet making the call:
function randomString(length, chars) { var result = ''; for (var i = length; i > 0; --i) result += chars[Math.round(Math.random() * (chars.length - 1))]; return result; } app.factory("MyYelpAPI", function($http) { return { "retrieveYelp": function(name, callback) { $http.jsonp("http://api.yelp.com/v2/search?term=food&location=San+Francisco&callback=JSON_CALLBACK", { params: { oauth_consumer_key: , oauth_token: , oauth_signature_method: "hmac-sha1", oauth_signature: , oauth_timestamp: new Date().getTime(), oauth_nonce: randomString(32, '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ') } } ).success(callback); } } });
source share