Tumblr OAuth in Emacs

2012-09-21

A week ago I complained that Tumblr API v1 is not supported anymore, and clients should use OAuth instead. The problem with OAuth is that it requires to setup a callback listener (Tumblr doesn't support out-of-band authorization unlike Twitter). It is not how most scripts and text editors are designed.

I figured how to do it in Emacs, though. I used oauth.el to handle OAuth part, and elnode to run a local HTTP server.

Source code: https://github.com/astanin/etumblr/blob/master/etumblr.el

How to use it:

  1. Register a new app; set "http://localhost:12345/" as callback URL, get the keys.

  2. In Emacs Lisp, after you install etumblr:

     (require 'etumblr)
     (setq access-token (etumblr-authorize-app
                         "OAUTH-CONSUMER-KEY" "SECRET-KEY" 12345))
    

This will lead the user through the entire authorization process, and will get you the access token (if the user permits).

  1. Now, you can use the API v2. There is a small function, provided as an example, to create new text posts on Tumblr:
    (etumblr-post-text access-token
                       "example.tumblr.com"
                       "post title" "*markdown* _body_")
    

Works for me.

I am not an elisp guru, and didn't figure how to pass the verification code from an async callback handler without using a global var. That's ugly but should probably work for most users.

Now, if someone finds time to integrate it with emacs-tumblr, I’ll be happy.

(Posted with etumblr.el, obviously)

P.S. More on Tumblr and Emacs integration. I discovered that tumblesocks supports API v2 too.

Update: I stopped using Tumblr, and don't intend to improve this code.