Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Javascript example

  • Loading branch information...
commit e769e952b3c6df5ca51304ded4b30e749f05cb5c 1 parent 0afeddd
@gabriel gabriel authored
Showing with 70 additions and 0 deletions.
  1. +70 −0 v2/js/search.html
View
70 v2/js/search.html
@@ -0,0 +1,70 @@
+<html>
+<head>
+<title>Yelp OAuth Example</title>
+<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>
+<script type="text/javascript" src="http://oauth.googlecode.com/svn/code/javascript/oauth.js"></script>
+<script type="text/javascript" src="http://oauth.googlecode.com/svn/code/javascript/sha1.js"></script>
+<script type="text/javascript" src="https://github.com/jamespadolsey/prettyPrint.js/raw/master/prettyprint.js"></script>
+<script type="text/javascript">
+var auth = {
+ //
+ // Update with your auth tokens
+ //
+ consumerKey: "YOUR_CONSUMER_KEY",
+ consumerSecret: "YOUR_CONSUMER_SECRET",
+ accessToken: "YOUR_TOKEN",
+ accessTokenSecret: "YOUR_TOKEN_SECRET",
+ serviceProvider: {
+ signatureMethod: "HMAC-SHA1"
+ }
+};
+
+var terms = 'food';
+var near = 'San+Francisco';
+
+var accessor = {
+ consumerSecret: auth.consumerSecret,
+ tokenSecret: auth.accessTokenSecret
+};
+
+parameters = [];
+parameters.push(['term', terms]);
+parameters.push(['location', near]);
+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/search',
+ 'method': 'GET',
+ 'parameters': parameters
+};
+
+OAuth.setTimestampAndNonce(message);
+OAuth.SignatureMethod.sign(message, accessor);
+
+var parameterMap = OAuth.getParameterMap(message.parameters);
+console.log(parameterMap);
+
+$.ajax({
+ 'url': message.action,
+ 'data': parameterMap,
+ 'dataType': 'jsonp',
+ 'jsonpCallback': 'cb',
+ 'success': function(data, textStats, XMLHttpRequest) {
+ console.log(data);
+ var output = prettyPrint(data);
+ $("body").append(output);
+ }
+});
+</script>
+</head>
+<body>
+
+</body>
+</html>
+
+
+
Please sign in to comment.
Something went wrong with that request. Please try again.