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
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%.
[tags]twitter, stéphane kattoor, curl, bash, shell, perl, script[/tags]
Hi Luke !
I’m happy my couple of hacks were useful for someone ;-)
Cheers
Stéphane
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. :)
A real man would have done this with netcat . . . ;-)
Nice job Luke!
I guess it could be done with netcat… I didn’t think about it.
Pingback: Twitter Tools Collection » Freakitude
[quote comment=”3377″]I guess it could be done with netcat… I didn’t think about it.[/quote]
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 :-)
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?
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. :)
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. :)
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! :)
@SmartAssProducts: Agreed. It is indeed faster. :) Also check this post.
@Cosmin Ghiu:
You could build a “follower-thanking” bot as a cron job that:
1. Capture your latest list of followers like so:
(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:
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.
How can I give a tweet with the source for example “Terminal”.
Default tweets have the source “web”, “IM”, “phone” or “Twitterific”
[quote comment=”11727″]How can I give a tweet with the source for example “Terminal”.
Default tweets have the source “web”, “IM”, “phone” or “Twitterific”[/quote]
You would have to get an API key.
[quote post=”1475″]How can I give a tweet with the source for example “Terminal”. Default tweets have the source “web”, “IM”, “phone” or “Twitterific” [/quote]
Richard Bronosky is correct. You need to obtain an API key by filling out this form:
http://twitter.com/help/request_source
Your application must then be approved by the Twitter team. They mostly decide whether to approve a request or not, based on the project website you submit. Yes, you have to build a custom app, and establish some web presence for it. Creating a Google Code project should be enough, as long as you have some deliverables available for download. That’s what I did.
More info, here.
Pingback: To Twitter or Not To Twitter… That is the Question « Techtv101.com
Thank you. I love tweeting with cURL. It was all I needed to get started with automatic tweets.
Thanks
Joemsie
Hello folks,
First good tut for startup,I wonder how secure is this method?
@ Cenk İlker İzanlı:
You are sending an update via standard http request – it’s not secure at all. If you use https on the other hand, it’s a different story.
Can’t get past “Basic authentication is not supported” Has the API changed?