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. P

Update 03/19/2007 08:19:21 PM

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:

  • Twimi
  • Posting Twitter Updates using Java
  • Twitter is useless to me.
  • Confession
  • Twitter With Me!
  • 5 Twitter Improvements I Would Like to See
  • Problems with the DOMParser (s4s-elt-character Error)
  • The Twitter Threading Problem
  • Need a Project
  • Jaiku

  • 12 Responses to “Posting Twitter Updates via Curl”

    1. Gravatar Stéphane UNITED KINGDOM Says: Reply to this comment

      Hi Luke !

      I’m happy my couple of hacks were useful for someone -)

      Cheers

      Stéphane

      Posted using Mozilla Firefox Mozilla Firefox 2.0.0.2 on Windows Windows XP
    2. Gravatar Luke UNITED STATES Says: Reply to this comment

      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 using Mozilla Firefox Mozilla Firefox 2.0.0.2 on Ubuntu Linux Ubuntu Linux
    3. Gravatar Craig Betts UNITED STATES Says: Reply to this comment

      A real man would have done this with netcat . . . -)

      Nice job Luke!

      Posted using Mozilla Firefox Mozilla Firefox 2.0.0.2 on Mac OS Mac OS X
    4. Gravatar Luke UNITED STATES Says: Reply to this comment

      I guess it could be done with netcat… I didn’t think about it.

      Posted using Mozilla Firefox Mozilla Firefox 2.0.0.2 on Windows Windows XP
    5. Gravatar Twitter Tools Collection » Freakitude UNITED STATES Says: Reply to this comment

      […] Posting Twitter Updates via Curl. Tutorial on posting an update to twitter using just curl and nothing else. […]

      Posted using WordPress WordPress 2.1.2
    6. Gravatar Stephane FRANCE Says: Reply to this comment

      Luke said:

      I guess it could be done with netcat… I didn’t think about it.

      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 on Debian GNU/Linux Debian GNU/Linux
    7. Gravatar Cosmin Ghiu UNITED STATES Says: Reply to this comment

      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 using Mozilla Firefox Mozilla Firefox 2.0.0.14 on Mac OS Mac OS X
    8. Gravatar Luke Maciak UNITED STATES Says: Reply to this comment

      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 using Mozilla Firefox Mozilla Firefox 2.0.0.14 on Ubuntu Linux Ubuntu Linux
    9. Gravatar Cosmin Ghiu UNITED STATES Says: Reply to this comment

      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 using Mozilla Firefox Mozilla Firefox 2.0.0.14 on Mac OS Mac OS X
    10. Gravatar SmartAssProducts UNITED STATES Says: Reply to this comment

      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 using Mozilla SeaMonkey Mozilla SeaMonkey 1.1.11 on Linux Linux
    11. Gravatar Luke Maciak UNITED STATES Says: Reply to this comment

      @SmartAssProducts: Agreed. It is indeed faster. ) Also check this post.

      Posted using Mozilla Firefox Mozilla Firefox 3.0.3 on Windows Windows XP
    12. Gravatar RichardBronosky UNITED STATES Says: Reply to this comment

      @Cosmin Ghiu:
      You could build a “follower-thanking” bot as a cron job that:
      1. Capture your latest list of followers like so:

      curl --basic --user $u:$p http://twitter.com/statuses/followers/$u.xml > ~/.twitter-$u-followers.temp

      (The > above should be a > char, but it’s getting caught by the WordPress)
      2. If there is no ~/.twitter-$u-followers.xml, jump to step 7
      3. Compare that to your previously saved* list of followers ~/.twitter-$u-followers.xml
      4. Exit if no diff
      5. Extract the screen_name field for each new follower
      6. Sent each new follower a tweet like so:

      for f in $new; do curl --basic --user $u:$p --data status="@$f Hey, thanks for following me. Where did you find out about me?" http://twitter.com/statuses/update.xml; done

      7. mv -f ~/.twitter-$u-followers.temp ~/.twitter-$u-followers # *this satisfies step 3.

      I’ll write a complete Bash script later, this is just off the top of my head. When I implement Step 5, I’m not sure if I want to just use sed or do a full blown xsltproc on it.

      Posted using Mozilla Firefox Mozilla Firefox 3.0.4 on Mac OS Mac OS X

    Leave a Reply

    XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <pre lang=""> <em> <i> <strike> <strong>

    [Quote selected]