Using the Google Slides API with Google Apps Script

Google recently announced the general availability of the Google Slides API. The announcement was accompanied by video from the new G Suite Dev Show presented by Wesley Chun embedded below, and a post by Wesley on Using the Google Slides API with Python. Wesley mentioned that “If you’re not a Python developer, it’ll be your pseudocode as you can use any language”, so that’s what I thought I’d do and share with you all in this post.


Update: Google recently announced that the Slides API has been added as an Advance Service, which removes the need to use the Slides Library generated by Spencer Easton. Some setup is still required in enabling the Slides API advance service. You still also need to enable the Slides API in your Google Developer Console project, illustrated below.

The Slides API is something that’s been on my wishlist for a while and the Google Apps Script community has already been getting it’s teeth into it. First I came across a post my Spencer Easton in which he released a Google Apps Script library to use the Slides API (Spencer’s genius is to have a script that generates these libraries from the Google’s API Discovery Service .. basically an API of APIs). This was followed by a post from Romain Vailard highlighting how his Form Publisher Add-on now also support Google Slides. Romain also had a nice tip that as long as you had a DriveApp call in your code you could use the access token with the Slides API.
So with these tips in mind I’ve created the snippet embedded below which includes Wesley’s code in the comments with the Google Apps Script equivalent. If you can’t be bothered with the copy and paste you can also make a copy of the final script project. In terms of setup there is not much to do and if you copied the script project you already have Spencer’s Slide API library enabled. The step I’m anticipating most people to trip up on is enabling the Slide API in the Google Developer Console so have included these steps in the .gif before the code.



Overall the Slides API seems to work well. One surprise is currently the CreateImageRequest needs an image url:

The image is fetched once at insertion time and a copy is stored for display inside the presentation. Images must be less than 50MB in size, cannot exceed 25 megapixels, and must be in either in PNG, JPEG, or GIF format.

This means you need a public url. I’m sure most developers could handle this, but I was surprised an option for a Google Drive file ID isn’t possible. As in Wesley’s example I’ve also got a file on Drive to use and to get a public url used another trick I got from Romain to use, remembering that the file needs to be shared to authentication isn’t required to view.
So lots of scope to doing interesting stuff with Google Slides now 🙂

Update: Spencer Easton has also noted that tokens generated from  using SpreadsheetApp will also work