Displaying Twitter Updates in Processing
In January, I’m going to be helping out the annual Martin Luther King Day events. A group of students and two faculty advisors met at the very beginning of Fall semester to start discussing ideas for this special day. We wanted to make it different from all the other years, more exciting interesting, and more ideas being communicated. It sounds like a fantastic opportunity to use the popular vibe of Twitter to our advantage! Without revealing too much of the magic that will be happening on the day, the essential idea behind this project is that tweets will be posted from a tweet-station on campus, and then displayed on a projected screen.
Getting twitter updates to be displayed in Processing would be able to help out on many other people’s projects too, so I created a quick and simple example on how to do so! The final product will look like this:

Let’s get stated- Go ahead and open Processing, creating a new sketch, and saving it.

The first essential item that we need is the Twitter4J library. It can be downloaded here.
Place the .jar file into a folder called ‘code’, then place that into the sketch’s folder.

The next step is the code, we’ll start out with the globals first.
String password = " "; // Add your password here
java.util.List statuses = null; // Setting up the statuses list
Twitter twitter = new Twitter(username, password); // Connecting to Twitter
int numberOfTweets = 10; // Number of status updates to get
String[] theTweets = new String[numberOfTweets+1]; // Storage area for the status updates
int tweetNumber = 0; // The status index that we will display (0 for most recent)
String theAuthour; // Name of the account
PFont font;
Be sure to insert your username and password between the ” and ” !
We will have two functions in this code… one to get the name of the Twitter account (not the username, but the actual ‘name’), and another to get the updates. First, the name of the account:
// Try-catch to ensure nothing horrible happens
try {
statuses = twitter.getUserTimeline();
} catch(TwitterException e) {
println(e.getStatusCode());
}
// Get the most recent status update
Status status = (Status)statuses.get(0);
// Get the name of the authour
theAuthour = status.getUser().getName();
}
All it does is it gets the most recent status update, and from there it can get the name of the account. Next, the updates:
// Try-catch to ensure nothing horrible happens
try {
statuses = twitter.getUserTimeline();
} catch(TwitterException e) {
println(e.getStatusCode());
}
// Get the 10 most recent status updates
for(int i=0; i<numberOfTweets; i++) {
Status status = (Status)statuses.get(i);
theTweets[i] = status.getText();
}
}
It goes and fetches the 10 most recent status updates, and stores them in theTweets[] for easy access.
Now that the basics are done… we can go and set up the actual fun stuff of the Processing sketch! :)
size(1525, 200);
background(0);
smooth();
font = loadFont("LovedbytheKing-48.vlw");
getAuthour();
getStatuses();
}
When we’re loading the font, be sure to make the font. There’s a description on how to make fonts here.
Now we get to display the info:
background(0);
// Displaying the name of the account
fill(255);
textFont(font, 36);
text(theAuthour + ": ", 100, 70);
// Displaying the status update
fill(255);
textFont(font, 36);
text(theTweets[tweetNumber], 50, 120);
}
That’s it! Test it out, hopefully it should run!
There are many modifications that can be made to this code… here’s some ideas:
- Change the colours
- Choose different tweets to display
- Change the tweet after a certain amount of time
- Split the string to format it
- … use your imagination! :)
Here is the archived sketch available for download:

Happy tweeting! Feel free to comment if there are any questions…
One of the problems that may occur is running out of API calls. For normal Twitter users, there is a limit of 120 API calls per hour. To read more about this, be sure to visit this page.
Useful links:
- Processing.org
- Twitter4J
- Twitter.com
- Twitter rate limiting
- Dafont.com (neat fonts!)