Created
July 23, 2010 15:27
-
-
Save kwhinnery/487581 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" | |
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> | |
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> | |
<head> | |
<!-- | |
Include Spazcore Twitter Configuration - your keys must be approved for xAuth: | |
http://dev.twitter.com/pages/xauth | |
--> | |
<script type="text/javascript" src="jquery-1.4.2.min.js"></script> | |
<script type="text/javascript" src="spazcore.js"></script> | |
<script type="text/javascript" charset="utf-8"> | |
// Include Twitter configuration - your keys must be approved for xAuth. | |
// More info: http://dev.twitter.com/pages/xauth | |
var SPAZCORE_CONSUMERKEY_TWITTER = 'consumerkey'; | |
var SPAZCORE_CONSUMERSECRET_TWITTER = 'consumersecret'; | |
</script> | |
</head> | |
<body> | |
<h1>SpazAuth example</h1> | |
<h3>Let's try authenticating with Twitter!</h3> | |
<label for="username">username:</label> | |
<input type="text" name="username" value="" id="username"/> | |
<label for="password">password:</label> | |
<input type="password" name="password" value="" id="password"/> | |
<button id="auth">Authenticate!</button> | |
<div id="results"></div> | |
<div id="timeline" style="display: none;"> | |
<button id="loadTimeline">Load timeline!</button> | |
</div> | |
<script type="text/javascript" charset="utf-8"> | |
//Configure Spaz authentication | |
SpazAuth.addService(SPAZCORE_ACCOUNT_TWITTER, { | |
authType: SPAZCORE_AUTHTYPE_OAUTH, | |
consumerKey: SPAZCORE_CONSUMERKEY_TWITTER, | |
consumerSecret: SPAZCORE_CONSUMERSECRET_TWITTER, | |
accessURL: 'https://twitter.com/oauth/access_token' | |
}); | |
var authPickle; // This will be a string which stores oAuth credentials for an account, | |
// serialized to a string | |
//Create authenticated tokens | |
$('#auth').click(function() { | |
var auth = new SpazAuth('twitter'); | |
var result = auth.authorize($('#username').val(), $('#password').val()); | |
if (result) { | |
$('#results').append("<h3>Access token key: " + auth.accessToken.key + "</h3>"); | |
$('#results').append("<h3>Access token secret: " + auth.accessToken.secret + "</h3>"); | |
$('#timeline').show(); | |
// Try saving OAuth to a string | |
authPickle = auth.save(); | |
} else { | |
$('#results').append("<h3>Failed!</h3>"); | |
} | |
}); | |
//helper function to display timeline | |
function renderTimeline(timeline) { | |
var html = ""; | |
timeline.forEach(function(tweet) { | |
html += "<h4>"; | |
html += "<strong>" + tweet.user.screen_name + ":</strong>"; | |
html += tweet.text; | |
html += "</h4>"; | |
}); | |
$('#timeline').empty().append(html); | |
}; | |
//Grab Twitter timeline using the Spazcore API | |
$('#loadTimeline').click(function() { | |
// Load OAuth from serialized string | |
var auth = new SpazAuth('twitter'); | |
auth.load(authPickle); | |
var twit = new SpazTwit({'auth':auth}); | |
twit.getHomeTimeline(null, 200, null, null, renderTimeline, function(){ | |
$('#timeline').append("<h3>Error loading timeline!</h3>"); | |
}); | |
}); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment