Node.Js Cron Job to Automatically Post Photo to Tumblr

Tumblr is a high ranking SMO website from where you drive traffic to your website or blog. In this article, we will cover how to create a Node.Js Cron Job to automatically post photo to Tumblr. You can post links or any other details as well in same way with different APIs.


Getting Tumblr Keys and Tokens

The first step is to get keys and tokens from Tumblr so you can use those to pass in their method of API calls.

Create an account and then an application at Tumblr. Go to Oauth Application Page to find the keys and tokens.

Follow my other article on step by step guide to get Tumblr Keys and Tokens.

Create Tumblr Client

Install the Tumblr package in Node.Js and create a client.

Require the tumblr.js package and use createClient method along with required parameters- consumer_key, consumer_secret, token and token_secret.

Call Tumblr Photo Post API In Node.Js to Post Photo

Further, you need to call the Tumblr Photo Post API which will post your photo with a description to the Tumblr dashboard.

Their createPhotoPost method requires some required parameters- blogName which will be your blog account name, params which will be an object of source URL of your photo and caption photo caption. The last parameter is a callback function in which you will get either error or success depending upon if the method ran successfully or not.

Setup a Cron Job to run Photo Post method automatically

The next and most IMPORTANT step is to setup a Cron Job which will post your photos / links to Tumblr at the given interval.

We will use “node-cron” package of Node.Js to setup a Cron Job.

Install node-cron package

Run the following command to install-

Schedule Cron in Node.Js

Schedule the Cron Job to run it at some specific time every day or as per your need. I am taking an example to run it once per day at midnight. You can change the Cron Expression to run it as per your requirement.

In the schedule method of the Cron, you need to call postPhotoToTumblr method which will run every time the cron runs. So in our case cron will run every day at midnight therefore photos will post to Tumblr every day at midnight.

Complete code

Here is the complete code of posting photos to Tumblr automatically using a Cron Job.

Conclusion

That’s it! We covered how to create a Cron Job in Node.Js to automatically post photos to Tumblr. You can check here how to post links to Tumblr. If any want to discuss more on it, reach out to my twitter profile.

4 thoughts on “Node.Js Cron Job to Automatically Post Photo to Tumblr

Leave a Reply

Your email address will not be published. Required fields are marked *