Thursday, September 11, 2008

The Twitter API - Addictively Easy To Use

I've started flagging particularly funny Twitter comments as they come by my feed. Such as this one from an hour ago:

Reading documentation... going to need 1.21 jigawatts of caffeine to get motivated for this.

When I started doing this, I wasn't quite sure what I was going to do with this collection of quips, or how I was even going to access them programmatically. Well, I still don't know what I'm going to do with them, but I've at least solved the second part - how do I access this data from a program.

I took a quick look at the Twitter AOI docs, and within just a few minutes, I had a good sense of how you get to data on Twitter. The API is actually drop dead easy to use.

To grab my favorites, I just need to visit the URL:

  http://twitter.com/favorites/i2x.format

The cool part is that format can be either xml, json, rss, or atom. After a minute or two of playing, I had the following command line going:

  wget -O - -o /dev/null 'http://twitter.com/favorites/i2x.xml' | \
  grep '' \
  | sed 's|||' | sed 's|||' \
  | sed 's/$/\n/' | sed 's/^/\n/' \
  | fmt

Which:

  1. Grabs my favorites from twitter in XML format
  2. Filters out all lines but the text
  3. Removes the XML tags
  4. Adds a newline to the beginning and end of each line, effectively double spacing the output
  5. Wraps the text into paragraphs using fmt

The output of the command is:

Reading documentation... going to need 1.21 jigawatts of caffeine to
get motivated for this.

My fortune cookie said ... "You will maintain good health and enjoy
life". Seems a little hard to believe after eating a thing of fried
rice

Nearly time for some Vitamin B. By "B" I mean "beers". By "Vitamin" I mean
"several".                                                                                                            

From a goofing around on the command line perspective, this API is hard to beat. And I could easily see embedding this in an application using either XML or JSON.

The whole Twitter user experience is incredibly lightweight - and it's great to see that they've continued that same spirit with their API.

Now, if I could just fine someone who was interested in me building a Twitter App, I'd be all set.

No comments:

Post a Comment