These past two months, I’ve helped two people start a tumblr blog. One of them is just a place for my daughter’s day care to share pictures of children with the parents. For obvious reasons, this blog is private. Tumblr is simple to use and the day care had no problem posting their photos and parents loved it. As I would find out, though, it is not possible to notify parents when a new set of pictures is published. So, I set out to write a quick code to do just that.
The Tumblr API is based on Oauth1.0a though you do not have to worry about OAuth to use it, the Tumblr PHP API does a lot of the work for you.
Since my script (called daily with a simple crontab) is windowless, I needed to generate a one time pair or tokens.
Tumblr provides the following Python script to do just that : callback.py.
So, first, let’s get some API keys :
You must register an app with Tumblr and, doing so, obtain a consumer_key and consumer_secret.
# I didn't have Python oauth module so
sudo easy_install pip
sudo pip install oauth2
# Log in Tumblr (with the account you'll need to be authenticated as for your API calls, in my case, day care admin
# Edit the callback script
# Edit the consumer_key and consumer_secret to put your own.
# Open the URL provided by the script in a browser
# Click on Accept
# Enter the redirect parameter value (as copied in the URL in your browser)
# The script displays your oauth_token and oauth_token_secret, copy and save them
Great, so, at this point, we have all we need to use the Tumblr API.
Get the PHP class from Git Hub and place it in your project directory.
CD in the tumblr project directory and, using composer, obtain the PHP dependencies
In your own project, inclue de composer/autoload.php file so that all other include to the dependencies work out of the box
Now, you can use the Tumblr API to get your blog’s list of post
Tomorrow, day care should post some great photos from last week field trip by a lake and all the parents will be happily notified 😉
In addition, I’ve tested the tumblr API and Composer. Not bad