You may have heard of Twitter - if not, it is a microblogging platform that allows members to tell each other what they are doing and what they think. There was a huge buzz about twitter recently - made me create an account on twitter. I tried to post through the web interface - but that's not a very intuitive method. The IM method is much better - but it almost never works. So I ended up making another method - the CLI method. Or twittering using the Command Line.
Before going any further, let me say that this method is for Linux. You can use this method in windows as well - but you have to install the windows port for curl. Even if you manage to get this method to work on windows, most of the major advantages of this method will be lost.
One of the main feature of twitter is the fast publishing time. You type something into a text box and click submit - and the stuff is published. That's fast! The only problem is that you need to open a browser and type in the URL to get to that text box. I need something faster. The IM method is a bit faster - but it rarely works. This situation will change in the future - but I don't want to wait.
The fastest method I can think of is like this - I press a keyboard combination and an small text box opens up. I type in the status and press Submit and this application will post the data to the twitter site using the Twitter API. The only problem is there is no such application. That's when I decided to do something about it. Of course, I am too lazy to create an entire application for it - so I had to settle for the next best method - posting from a terminal.
Posting from a Terminal
I have configured my system to open the Terminal(konsole) when I press Ctrl+Alt+A. Now all I have to do is create a command, say, 'twitter' that will publish the command line arguments to the twitter site. My input will be something like this.
twitter "Using the CLI Twitter client"
That's fast enough for me.
To create the script, I took a look at the twitter API...
All of the methods (except for the public timeline) require user authentication via Basic Auth. The username is the email address you have stored on Twitter, the password, your password.
Updating your Twitter
Done with a HTTP POST using the "status" parameter. status=Walking the dog.
The simplest API I have ever seen.
After I saw that API, I realized that I don't need to do any coding to create the application - I just need to use the curl command. curl is a tool to transfer data from or to a server. All I have to do is execute this command...
curl --basic --user "<User>:<Password>" --data-ascii "status=<Twitter status>" "http://twitter.com/statuses/update.json"
In my case it will be
curl --basic --user "binnyva:******" --data-ascii "status=Using Twitter from command line" "http://twitter.com/statuses/update.json"
The Twitter Shell Script
But I don't think you would like to type all that everytime you want to twitter. So we have to put it into an executable file. Also, we have to modify the script to enable the support for command line arguments.
curl --basic --user "<User>:<Password>" --data-ascii "status=`echo $@|tr ' ' '+'`" "http://twitter.com/statuses/update.json"
Replace the <User> and <Password> with your twitter user id and password. Now save the text to a file called 'twitter' and give the file execute permission. Put this file in any folder in your path(like
Using Twitter CLI
Just call the command with your message as the argument - like this
twitter Writting Content for Bin-Blog about twitter. twitter "Using Twitter CLI"
For best results, enclose the message within quotes. This will prevent problems when using wild card characters like '?'
Before I leave, how many of my readers are twitter users? OK, you three - leave a comment with your twitter ID. By the way, I am binnyva.
Another thing - this script is thrown together in a very short time - is there a better, more foolproof way of doing this? If you know one, leave a comment.