Data, Maps, Usability, and Performance

Automate SlideShare Creation with JavaScript and APIs

Last updated on November 26, 2014 in Development, Social Media

programmatic automation

I am a big fan of SlideShare and automation so today I want to show how you can programatically create a slideshow with JavaScript and upload it to your account with the SlideShare API. I am going to use jsPDF to generate a PDF file from images and text. When the pdf is created, I will use the upload_slideshow API call to upload the pdf into awesome slides on SlideShare. And the slides will be the actual steps to do this. Let’s start.

jsPDF supports all kinds of inputs from text, shapes, images, to complete HTML but for this demo we will just focus on text and I will add one image for fun. The image needs to be in Data URL format and you can do that programmatically via CANVAS.toDataURL() method or an online tool like dataurlmaker. I will be using a smaller version of the image for this post in my first slide with the title “Create Slideshows Programatically.”

Here is the code that automates the pdf creation

Since the SlideShare API does not allow CORS, we need to either proxy the API request through server side or just use cURL. If you looked at the source code of the link above you will see I commented out the doc.save() call as it downloads a pdf to the filesystem. If you uncomment it, you will have a pdf file ready to send over to SlideShare and you can even schedule this via a cron job.

Once you grabbed an API key, you can make a POST call via cURL with a PHP script. You need the key whitelisted and there are some interesting Authentication requirements (using timestamps and SHA1 hashes) but the following PHP code with cURL worked well:

Tags: ,

Facebook Twitter Hacker News Reddit More...