Twitter and Processing

Yes, I’ve finally gone and done it. I have twitter. it was a long time coming but now I want to make the most of it. So within minutes of logging on I found a nice set of Java API bindings and got writing.

I wanted to quickly make something that would grab a load of simple data from my twitter account and display it in a meaningful way. So my first approach was to add the Processing core package into the class path. I’m really impressed by Processing because I can mock up an animation / visualizer really quickly just by feeding it data.

With Processing in the mix I decided to make a visualizer  for my followers and those who I follow. I wanted it to show them moving around the screen and maybe somehow show any links that may exist between them. It would be really cool to see any links between my friends that I didn’t know about. 

I started with the basic JFrame and embedded PApplet. From here I  gave the applet a nice black background and went about grabbing the data from Twitter. I used the Twitter4j bindings found here. It was recommended on the Processing Discourse and provides some really nice tools to easily get simple data from the twitter servers. 

Using the Java bindings I was able to do several things. First I logged in by passing the username and password of the user to Twitter. I then retrieved all of the users followers and all of the users that they are following. This data is all returned as a List cast to User type. I created an inner class allowing me to store an x and a y position for these users within the PApplet. I stored instances of this class in ArrayLists for quick and easy access.

So with all of the data I needed, stored away, I went ahead and displayed it. This was the easy bit, performing most of the animation etc within the draw method.

So here it is, I’ve called it pTwitter (I’m sure I’ll come up with a better name later!) Completed within 3 hours on and off. My next steps are going to be drawing symbolic lines between users who are associated in some way.

 

pTwitter

Edit: The blue bar at the bottom and all buttons are from the ControlP5 library. The allow the user to update their status directly from the app.

~ by jamssn on April 13, 2009.

4 Responses to “Twitter and Processing”

  1. Hello!

    Did you face any security problem using twitter4j inside a applet. Could you please help me, I am trying to run a simple example with applets and twitter4j, but it is not working.

    Thanks!

    • Hmm, I don’t remember having any problems with security. If you’re using a Mac / *nix system check the ip tables etc to see if it’s blocking the twitter app. If your having problems with logging into twitter, check the documentation for instructions on how to create an authenticated session.

  2. Thank you for your reply! =D

    But just a few more questions:
    Did you deploy your application and placed the applet in a html file and did you try to run it from the browser or did you just open in an applet viewer?

    Thanks!

  3. At the moment I just run it in the applet viewer. But it’s also really easy to then deploy it within a browser with the correct html tags.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

 
Follow

Get every new post delivered to your Inbox.