Files
oauthsimple/js/index.html
T
2008-11-16 16:55:21 -08:00

78 lines
3.3 KiB
HTML

<html>
<head>
<title>OAuthSimple test document</title>
</head>
<body>
<h1>test document</h1>
<ol>
<li><a id="sample1">First Link</a>
<li><a id="sample2">Second Link</a>
<li><a id="sample3">Third Link</a>
</ol>
<div id="hasConsole" style="display:none">Psst! Open your firefox console for the output objects.</div>
<a href="OAuthSimple.js">The javascript file</a>
<script src="OAuthSimple.js" ></script>
<script>
// To get results in all their magnificent glory (rather than some error)
// fill these out with your own magical Netflix API keys.
// Don't have a magical Netflix API key yet?
// http://developer.netflix.com
//
var apiKey = "nO-woRk";
var sharedSecret = "ExAMple01";
var accessToken = "This-Will-NOT.wOrk.EIthEr";
var tokenSecret = "N0sOuP4U";
if (apiKey == "nO-woRk")
alert('Remember, the key/values defined here need to be changed to valid values before the API calls will work. Currently, these links are only for demonstration purposes.');
var argumentsAsString = "term=rat&expand=formats,synopsis&max_results=1&boo=foo&boo=bar";
var argumentsAsObject = {
term:'rat',
expand:'formats,synopsis',
max_results: '1',
boo: ['foo','bar'] //there are some webapps that take an array this way.
};
var path="http://api.netflix.com/catalog/titles"
// The hard way...
var oauth = OAuthSimple(apiKey,sharedSecret);
oauth.setParameters(argumentsAsString);
oauth.setPath(path);
var sample1Results = oauth.sign();
if (window.console != null)
console.debug('Sample 1',sample1Results);
// the semi-easy way.
var oauth2 = OAuthSimple(apiKey,sharedSecret);
var sample2Results = oauth2.sign({action:'GET',
path:path,
method:'HMAC-SHA1',
parameters:argumentsAsObject});
if (window.console != null)
console.debug('Sample 2',sample2Results);
// the totally easy way.
var sample3Results = OAuthSimple().sign({path:path,
parameters:argumentsAsObject,
signatures:{
'consumer_key':apiKey, 'shared_secret': sharedSecret,
'access_token':accessToken,'access_secret':tokenSecret}});
if (window.console != null)
console.debug('Sample 3',sample3Results);
// Now fill out the samples with our handiwork:
document.getElementById('sample1').href = sample1Results.signed_url;
document.getElementById('sample2').href = sample2Results.signed_url;
document.getElementById('sample3').href = sample3Results.signed_url;
if (window.console != null)
document.getElementById('hasConsole').style.display='block';
</script>
</body>
</html>