Command line Twitter script

I mentioned on Twitter the other day that I have a relatively basic but functional command line Twitter script, for use when you can’t or just don’t want to load the full-fat Twitter site in your web browser or you don’t want to use a third party GUI client. I received much more interest in this than I thought I would (i.e. more than zero) and so after some thought* I’ve decided to make it available to anyone who wants it.

The script, which supports a single Twitter account, supports the following actions:

  • Update (tweet), with option to specify an existing update ID to reply to.
  • Retrieve your public timeline (your tweets and those of who you follow).
  • Retrieve your own timeline.
  • Retrieve the public timeline.
  • Retrieve your recent mentions.
  • Retrieve recent re-tweets of your updates.
  • Search Twitter.

In order to work, you must authorise your Twitter account with SuperTweet, and provide the script with the username and secret that you specify in your SuperTweet account. This is because the script does not support oAuth (at least, not yet). Also, if you use Twitter to post URLs (and you probably do) you will also require a Bit.ly API key. Edit the script and provide both sets of credentials at the top.

The script is self contained, containing all the various classes that it depends on in the same file. I’ve verified that it works “out of the box” on Ubuntu Linux 10.04 and Mac OS 10.6. It will probably work on many other systems too, assuming they have PHP installed. With a small modification to the first line you can probably get it to work on Windows too, but that’s as far as I can advise, you’re on your own from there. The version I use doesn’t contain the included classes as I link it to my local class library.

To get started, download the script, unpack it with gzip -d, add execute permissions with chmod +x and then type ./twitter.php commands for a usage summary. Some commands when called without arguments will present further usage summaries which will tell you how to use them. You’ll probably want to start with something like:

./twitter.php update "Testing @stuartford's pitiful command line Twitter script."

Don’t forget to add your Twitter and Bit.ly credentials to the top of the script otherwise it definitely won’t work first time for you and I’d rather that didn’t happen.

If you don’t understand most of this post then this script probably isn’t for you, sorry, it is what it is, no warranty, etc.

* I say it required some thought because it’s rare that I make my code available for public use. I don’t know why, because I believe I am a talented software developer, I guess it might be the slight family creative gene within me that might be forcing a behaviour equivalent to an artist who’s perpetually reluctant to show people his work, who knows, that’s one for the shrink’s chair. Certainly the script isn’t my best work, it grew out of something quick and dirty, and as any developer will tell you, anything that grows out of something quick and dirty will always be quick and dirty at its heart.