Personal Log;Logdate: 1850

As part of a larger intellectual exercise, I started investigating the viability of posting to Tumblr programatically. The old (V1) API is pretty simple to use but lacks security; not to mention: it’s the oldAPI. So API V2 it is. In order to access a large portion of the V2 API, you need to use OAuth for the authentication. This means that you can grant access to applications and revoke access individually.

Getting an application set up to use OAuth is a multi-step process (outlined here) but basically works like this:

Some services may do most of this work for you, but Tumblr does not. When you register an application, one of the fields you fill in is the ‘callback url’. This is the URL that you will be directed to after you authorize a token for that application. When this happens (and if you’re setting up this application for your own use, it doesn’t matter where you’re redirected to) you’ll be provided with a oauth verifier token (VIAURL parameter). For my own simplicity sake, I put a PHP script on my web server that would echo the contents of that parameter:

<?phpecho$_GET["oauth_verifier"];?>

I accidentally found a Perl script meant for walking you through the process of getting tokens. For useability sake, I made some slight modifications to the script to make it a little more extensible and you can get it here.

Running this script will require that you at least set the consumer key and consumer secret but these are the configurable options:

Now that you have the consumer keys and access tokens, you can post to Tumblr!
There are already several modules that will handle OAuth requests. I wanted to stick with something simple, so I stuck with the LWP::Authen::OAuth. This module makes it very easy to make OAuth requests, since you provide it with the information it needs for the authentication and the request itself and that’s it. The following code is a snippet of what I was using; it also prints the contents of the request just so I could see what was happening:

Comments

Hey man, great tutorial! I’ve really been digging into the tumblr API with perl, but I’ve had one giant hiccup – photo uploads. My data is local, so I have to use the “data’ parameter. The tumblr API page does a poor job saying exactly what they want in the data parameter. Have you been able to upload images to Tumblr successfully?

Thanks for the write up. I had trouble to extract the correct oauth_verifier token as I did not know, that I’m not allowed to add the #_=_ at the end of the token url string.
A hint about this would be cool. Or to extract this in the GetToken.pl script from the complete URL returned by tumblr :-)