Leveraging Twitter's API and Google's JS Library API
So, in the past half hour I’ve been working on getting the widget at the top-right working. I like it better than the badges twitter provides.
It makes use of the Twitter API, and Google’s recently launched JS Library API.
Here’s the code (or you can look at the bottom of the page source):
If you want to re-use it, replace twitterUsername with your twitter username.
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js"></script>
<script type="text/javascript">
var twitterUsername = 'broady';
$(document).ready(function() {
$.ajax({
dataType: 'jsonp',
url: "http://twitter.com/statuses/user_timeline/" + twitterUsername + ".json?callback=twitterCallback"
});
});
function twitterCallback(data) {
var found = false;
$.each(data, function(){
if (this["text"].indexOf('@') != 0 && !found) {
$('#twitter').text(this["text"]);
found = true;
}
});
}
</script>
Wed, 28 May 2008 13:03
Tags api, google, javascript, twitter
1 comment »
-
By Alex G about 1 year later:
Very nice… I was thinking it should be a 30 minute job and a few lines of code, you proved me right, except thanks to you it took 1 minute google search and cut and paste instead :)