Leveraging Twitter's API and Google's JS Library API

May 28

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>
Trackbacks

Use the following link to trackback from your own site:
http://chrisbroadfoot.id.au/trackbacks?article_id=leveraging-twitters-api-and-googles-js-library-api&day=28&month=05&year=2008

Comments

Leave a response

Leave a comment…