tumblr_logo

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.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# 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

vi /path/to/callback.py

# Edit the consumer_key and consumer_secret to put your own.

python /path/to/callback.py

# Open the URL provided by the script in a browser

# Click on Accept

Press y

# Enter the redirect parameter value (as copied in the URL in your browser)

Press Enter

# 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

1
composer install

In your own project, inclue de composer/autoload.php file so that all other include to the dependencies work out of the box

1
require_once composer/autoload.php

Now, you can use the Tumblr API to get your blog’s list of post

1
2
3
4
5
6
7
8
$client = new Tumblr\API\Client($consumer_key, $consumer_secret);
$client->setToken($oauth_token, $oauth_token_secret);

$resp = $client->getBlogPosts($blogName, $options = array("limit" => 5));
if (is_array($resp->posts)) {
foreach ($resp->posts as $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

Filed under: Me myself I, PHP

Tagged with: , , , ,

Liked this page?

Tweet it

Subscribe to the RSS feed or sign up for the newsletter now.

Posts related to Notify readers of a private tumblr blog by email

Name (required)

Email (required)

Website

Leave a Reply

  • About Me


    photo of Samantha Halfon Samantha Halfon
    Software Engineer
    blueKiwi software
    Paris, France
    I enjoy playing with my computer(s), listening to Bob Dylan (and related artists) and watching movies (especially if they were directed by Martin Scorsese or John Cassavetes). Sometimes, I play a little guitar... If not doing any of the above, I am either riding a small red bike around Paris, or, making videos. About my videomaking please check out World Wide Angle and its blog.