<!--
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.
-->
<html>
<head>
<title>Yelp OAuth Example</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/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://raw.github.com/padolsey/prettyPrint.js/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",
// 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 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);
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);
var output = prettyPrint(data);
$("body").append(output);
}
});
</script>
</head>
<body>
</body>
</html>
<div class="line">when i try to run the code in my aspx page. i get "Microsoft JScript runtime error: 'console' is undefined" this error..</div> <div class="line"></div> <div class="line">i put all the key fields.. but i get this error in my code. could
you please tell me how can i get the contents using this code or making the url..</div> <div class="line" id="LC78"></div>
Sheikhans
Member
47 Points
85 Posts
how to create API URL using some credentials
May 09, 2012 05:11 AM|LINK
Hi.. i am having a problem.. i need to make an api url which returns me jason data. when i paste that api url in my browser.
i am having api fields of yelp.com here is the url
and here are some fields. which i have YWSID, Consumer Key,Consumer Secret, Token, Token Secret
can somebody please tell me how can i use these keywords with url and get the result page in the browser.
your help will be turly appriciated.
Ans.
nijhawan.sau...
All-Star
16432 Points
3174 Posts
Re: how to create API URL using some credentials
May 09, 2012 05:39 AM|LINK
It depends on how yelp.com has exposed their API.
If they are expecting these keywords in querystring, then just build a url and add querystrings to it.
Sheikhans
Member
47 Points
85 Posts
Re: how to create API URL using some credentials
May 09, 2012 07:36 AM|LINK
here is their java script code:
<!-- 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. --> <html> <head> <title>Yelp OAuth Example</title> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/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://raw.github.com/padolsey/prettyPrint.js/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", // 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 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); 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); var output = prettyPrint(data); $("body").append(output); } }); </script> </head> <body> </body> </html><div class="line">when i try to run the code in my aspx page. i get "Microsoft JScript runtime error: 'console' is undefined" this error..</div> <div class="line"></div> <div class="line">i put all the key fields.. but i get this error in my code. could you please tell me how can i get the contents using this code or making the url..</div> <div class="line" id="LC78"></div>