Laravel Tumblr API Integration

Laravel Tumblr API Integration

Posted on:April 17, 2019 at 10:00 AM

Tumblr is one of the famous microblogging and social networking website. If you are a fan of Tumblr and planning to use its official API. In this post, I mainly focus on how to integrate with Laravel.

Table of Contents

Open Table of Contents

Install

First of all, you need to install the package with composer.

composer require tumblr/tumblr

Now run -

composer update

You have already installed the package. Now let’s integrate.

Integration

Just declare a new route-

Route::get('/tumblr', 'TumblrController@index');

Now you need to have api_key and secret_key to connect. You need to register it in your Tumblr Apps.

Once you have it, then go to the this link and get oauth_token and oauth_token_secret.

You probably will get something like this-

// Authenticate via OAuth
$client = new Tumblr\API\Client(
            'api_key',
            'secret_key',
            'oauth_token',
            'oauth_token_secret'
);

// Make the request
$client->getUserInfo();

Now copy that code and paste in the controller, that will be like this. In this example, I am creating a new post and publish it in Tumblr.

public function create()
    {
        $client = new Tumblr\API\Client(
            'api_key',
            'secret_key',
            'oauth_token',
            'oauth_token_secret'
        );

        $blogName = 'name-of-your-blog';

        $data = [
            'title' => $title,
            'tags' => $tags,
            'thumbnail' => $thumbnail,
            'url' => $url,
            'type' => 'link'
        ];

        $client->createPost($blogName, $data);
    }

Now once you browse this http://127.0.0.1:8000/tmblr, you will have a new post in your Tumblr blog.

You will get the full list of Tumblr API methods here.

Thank you. :)