Posting Twitter Updates via Curl
Here is how to post an update to twitter using just curl and nothing else. I guess you can use this if you are working on some headless unix machine that doesn’t have a proper browser… Of course a machine that has curl would also probably have lynx or elinks but I digress.
Here is how you update twitter with curl:
curl --basic --user username:password --data status="I'm twittering with curl!" http://twitter.com/statuses/update.xml
That’s it! That’s all you have to do. I was actually quite surprised when I found out it’s this easy. And yes, I can’t take any credit for discovering it - I shamelessly stole the idea from Stéphane Kattoor. If you read Stéphane’s post, you will see that the relative ease of posting regular updates, is balanced by totally super retarded mechanics of sending direct messages.
It turns out that curl is not the best way to send them - perl + lwp is.
Based on Stéphane’s notes I wrote a this bash script that lets you send updates. I suppress the xml output and you get the standard curl time counter when you post (let’s say this is a poor man’s progress bar ok?):
#!/bin/bash
read -p "What are you doing? " -e input
curl --basic --user username:password --data status="$input" http://twitter.com/statuses/update.xml > /dev/null
echo "OK"
I’m using the read function, but I could easily convert this to use Xdialog or another graphical input grabbing tool. It would also be worthwhile incorporating Stéphane’s perl script for direct messaging while I’m at it.
Heh… I could actually combine this with my time logging script and have it pop-up and nag me for input every n hours.
Here is the windows version of the script:
@echo off
SET /P input="What are you doing? "
curl --basic --user username:password --data status="%input%" http://twitter.com/statuses/update.xml > NUL
echo OK
You will have to download curl, and drop it somewhere in your %Path%.
Related Posts:


March 20th, 2007 at 10:15 am (3371) [Quote]
Hi Luke !
I’m happy my couple of hacks were useful for someone
Cheers
Stéphane
Posted usingMarch 20th, 2007 at 10:38 am (3372) [Quote]
Once again thanks for posting this. I love being able to post the updates via curl - and I can easily incorporate this into all kinds of other scripts allowing them to post stuff to twitter.
Posted usingMarch 20th, 2007 at 11:46 pm (3376) [Quote]
A real man would have done this with netcat . . .
Nice job Luke!
Posted usingMarch 21st, 2007 at 1:00 am (3377) [Quote]
I guess it could be done with netcat… I didn’t think about it.
Posted usingMarch 21st, 2007 at 3:39 am (3381) [Quote]
[…] Posting Twitter Updates via Curl. Tutorial on posting an update to twitter using just curl and nothing else. […]
Posted usingMarch 25th, 2007 at 4:30 am (3476) [Quote]
Luke said:
It can certainly be done with netcat, but that won’t be without pain ! Having to manage the session cookies ? I prefer to leave it to curl
Posted using Debian IceWeasel 2.0.0.1 onMay 5th, 2008 at 3:02 pm (8965) [Quote]
great blog post. being a programming newbie to twitter was curious to build a small bot that did an auto-reply like post to twitter once a new a new user has followed me. it be something like: @user thank you for following me
would this type of coding work for this?
Posted usingMay 5th, 2008 at 3:18 pm (8966) [Quote]
Yes, you could use it to send the auto-reply but that’s just half of the problem. You would also need some way of detecting that someone followed you either by querying the twitter API or by using some sort of email filter to trigger it when follow notification comes in.
So what you are trying to do seems a bit more complex.
Posted usingMay 5th, 2008 at 4:17 pm (8967) [Quote]
thanks for the reply. i knew it wasnt easy since i dont see one available anywhere online. lets see what my coding ninja skills can do.
Posted usingOctober 1st, 2008 at 7:40 pm (10298) [Quote]
I’ve been using this method and just stumbled upon your page while looking for similar methods. One thing I want to point out is that–at least for me and the many other *nix geeks I know who also Twitter from a command line–it has nothing to do with “some headless unix machine that doesn’t have a proper browser…” We use it because it’s QUICKER! I have at least 15 very nice browsers, thank you, but NONE of them is as quick as typing: twitter [my message] (I named the shell script I wrote twitter.) So, yeah!
Posted usingOctober 1st, 2008 at 7:51 pm (10299) [Quote]
@SmartAssProducts: Agreed. It is indeed faster.
Also check this post.
Posted using