Thursday, October 08, 2015

Running twurl on Windows

This post will sound ridiculous to some people, "what's so hard about running twurl on Windows"? Actually nothing, once you know what to do.
Twurl (OAuth-enabled curl for the Twitter API) is a very helpful command line utility used to reach out to the Twitter API. If you're familiar with the twitter API and basically any OAuth API, handling the signing of every request can be painful, at least until you get it right the first time.

I use twurl to see what an actual good request to the API looks like, so after I get the good sample I use fiddler to debug my shelltwit requests and compare the two of them.

So, how do I use twurl? There are many ways, being one of them getting the source files and building the project yourself out of Github.
But probably the easiest way is to use the "compiled binary" (actually, it is not a binary nor compiled).

Twurl can be installed as a Ruby Gem. What does that mean? I have no idea. Well, I do have an idea but a really good way of explaining since I'm not a Ruby wiz.
Cut the crap already!!! okay, okay, I'll assume you're familiar with Chocolately, if you're a Windows "power user" you really need to get to know it.
So, first things first... you need to install the Ruby environment on your machine, so, open your favorite command line shell as Administrator and type

choco install ruby

There, ruby is now installed. Now you need to install twurl and since it's a Ruby gem this is what you you need to do

gem install twurl

And that's it, that will install the twurl gem and now you can use twurl from your command line to, for instance, upload an image to twitter like the following

twurl -H -X POST "/1.1/media/upload.json" --file "/path/to/media.jpg" --file-field "media"

Cool uh! Let me know if you found this post useful


cguitar said...

Thank you very much!

I followed the steps and had twurl installed. But when I use my python code, it still cannot import twurl, saying ' No module named twurl'...

Jonatan Van Hove said...

this was hugely helpful. Just fyi: run CMD as admin, and close it after every step to ensure it all works as intended. the Twurl github page has info on authentication which you'll need too:

Anonymous said...

I get the below error while executing choco install ruby
'choco' is not recognized as an internal or external command,
operable program or batch file.

sebastian gomez said...

If you did install Chocolatey make sure you restart (just in case)

Siddhant Shenoy said...

A great article, thanks! Although this is an old post, I am working with the Twitter API right now and this was extremely helpful!

sebastian gomez said...

I'm glad it has been a helpful post for almost three years now.
I continued with my shelltwit project and I have been implementing many endpoints of the Twitter API. Just in case it helps others, you can take a look at it at