Note: This code is deprecated as of the Twitter API version 1.1. It should still work if you add in the authentication.

As I completed the next release for the HRU app today, I was in the mood for some more web programming. Figured out that I should make a Twitter integration for my website, as I don’t like the Twitter badges or the WordPress plugins for it. This little snippet calls the Twitter API and displays the 10 latest tweets of the user. This code snippet can be used anywhere that supports JavaScript and HTML.

To change the account, tweet count or what Twitter messages you want, just edit the address in the getJSON() call.

div#tweetHeader {font-weight:bold;}
div#tweetContainer {width:200px; padding:0px;}
a.twitterLink {color:black;}

<div id="tweetContainer"></div>

<script type="text/javascript" src=""></script>
<script src=""></script>
<script type="text/javascript">

var tweets = new Array();
var currentTweet = 0;
var tweetTimer;

$(document).ready(function() {
    $("#tweetContainer").mouseover(function() {
    $("#tweetContainer").mouseout(function() {
        tweetTimer = setTimeout(function(){

function getTweets() {
        function(data) {
            for(var i in data) {
                var formattedString = data[i].text.replace(/((http|https):\/\/[^ ]+)/g, '<a class="twitterLink" href="$1">$1</a>');
                formattedString = formattedString.replace(/([#@][^ ]+)/g, '<a class="twitterLink" href="$1">$1</a>');
                tweets[i] = formattedString;

function updateContainer() {
    $("#tweetContainer").hide("slide", {direction: "left"}, 1000, function() {
        $("#tweetContainer").show("slide", {direction: "right"}, 1000);
        currentTweet = ((currentTweet+1) % tweets.length);

    tweetTimer = setTimeout(function(){