12

I'm wondering if there may be a way to programmatically create presentations in Google Slides. So for example if underlying data changes I can just refresh the deck without lots of copy paste for all the charts etc.

Something similar to using like markdown and R slidify to produce data driven PDF presentations. My end product needs to be a nice pretty Google Slides presentation.

Is this the sort of thing I could use the Google Drive API for? I'm not sure if App Script can be used for Slides like you can for Sheets.

Am hoping it's a common enough problem that a solution exists.

One option is to just automatically produce a PDF and then manually import into Google Slides. Problem is that this approach is a bit limited due to errors on conversion and lack of other Slides functionality.

Any input much appreciated.

Kos
  • 4,890
  • 9
  • 38
  • 42
andrewm4894
  • 1,451
  • 4
  • 17
  • 37

4 Answers4

12

It's 2018, and great news (and answers!) to this older question:

  • The Google Slides REST API launched in Nov 2016... here is its launch post and 1st developer video I made to get you started. A shorter code sample than the video's is the Quickstart in the docs (available in a variety of languages). If you're new to Google APIs, I recommend you watch this video, then this one, and finally this one first to get an idea of how to use them. The code samples are in Python, but if you're not a Python developer, just pretend it's pseudocode because many languages are supported by Google APIs Client Libraries. :-)
  • If you code in JS and want to have Google host+run your app, the Slides service in Google Apps Script launched in Sep 2017... here is its launch post and 1st developer video I made to get you started. This is also the same technology behind Slides Add-ons. If you're new to Apps Script, I recommend you watch this video to get an idea of what it is and how to use it. Then check out its video library for more examples of using Apps Script. (Admittedly, it's easier to code w/Apps Script vs. the REST APIs, making it more "addictive" for developers... you were warned!) :-)
  • Additional videos on programmatically accessing Google Slides can be found via its developer video library. Videos on this and other G Suite developer technologies can be found in the G Suite Dev Show series which I produce.
  • There's no video for this, but there's an open source Markdown-to-Google Slides generator (written in Node.js) my colleague created that you may be interested in, representing one of the "reference apps" using the Slides API. You can find more about this app as well as others on the Samples page of the documentation.
  • No video for this either, but Node.js developers who want to get up-to-speed quickly learning how to use this API should try the Slides API codelab where you build an app that uses Google BigQuery to analyze open source licenses and generate a report presentation... letting you learn TWO Google Cloud technologies with one tutorial! :-)
wescpy
  • 10,689
  • 3
  • 54
  • 53
7

The Google Slides API was launched on 11/9/2016. It provides the ability to read, create, and edit Google Slides presentations.

At the moment there still isn't an equivalent service in Apps Script, but you can use the Apps Script OAuth2 library and UrlFetchApp to make calls to the API within a script.

Eric Koleda
  • 12,420
  • 1
  • 33
  • 51
2

An example from Apps Script:

Enable the Slides API in the developer console:

  1. Click on Resources > Developers Console Project > [Your_Project_Name].
  2. Click on Enable API, search for Slides and enable the Slides API.

Use UrlFetchApp to send authenticated requests to the Slides API

As a simple example from within Apps Script, consider fetching the latest version of a Presentation (presentations.get).

// Add your presentation ID
var presentationId = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';

// Force add the Drive scope (as this comment *will* get parsed
// and trigger a popup to authorize Drive access)
// DriveApp.createFile('') 

// URL formed as per the Slides REST documentation
var url = 'https://slides.googleapis.com/v1/presentations/' + presentationId;
var options = {
  headers: {
    Authorization: 'Bearer ' + ScriptApp.getOAuthToken()
  }
};
var response = UrlFetchApp.fetch(url, options);

// Turn this back into a JS Object so it can be used.
var presentation = JSON.parse(response.getContentText());

// Log the ID of the presentation
Logger.log(presentation.presentationId);

// Log the number of slides...
Logger.log(presentation.slides.length);

// Loop through the slides
var slides = presentation.slides;
slides.forEach(function(slide) {
  // ... do something with each slide...    
});

The structure of presentation is also documented in the REST reference. Armed with the REST reference, this example can be extended to be used with any Slides API request and response.

Bardy
  • 2,100
  • 1
  • 13
  • 11