Slides API refusing to connect to script; Project: consolidating multiple slides into a single one

57 views
Skip to first unread message

Marco D'Souza

unread,
May 18, 2024, 2:46:10 AMMay 18
to Google Apps Script Community

Hey good people,


Before I get to my ask, a bit of a background on what i’m looking to achieve:

  1. I have a Google Sheets file in which I maintain a list of entries (250-300)

  2. Each entry is a song name

  3. Each song name is referenced (by Document ID) to its own Google Slides file containing its lyrics (often spread across multiple individual slides)

  4. Each song entry has a checkbox that is meant to select/deselect that song

What I’m trying to achieve is:

  • Create a script that runs through this spreadsheet, picks up only the slides referenced by the selected name entries 

  • Consolidates all of the individual song lyrics from the slides, into a single setlist presentation.

  • Bottomline: A karaoke listing of the lyrics of all the selected songs. 


The Google Apps Script code (that Gemini largely helped come up with!):


function consolidateSlides() {

 // Get selected checkboxes (assuming checkboxes are in column A)

 var sheet = SpreadsheetApp.getActiveSheet();

 var selections = sheet.getRange("A:A").getValues(); // Adjust range if your checkbox column is different

 // Create a new presentation (optional)

 var newPresentation = SlidesApp.newPresentation();


 // Initialize variables

 var presentation = null;

 var slides = [];


 // Loop through selected checkboxes

 for (var i = 0; i < selections.length; i++) {

   if (selections[i][0]) { // Check if checkbox is selected (TRUE)

     // Get the document ID from column C (adjust index if needed)

     var documentId = sheet.getRange(i + 1, 3).getValue(); // Assuming IDs are in column C


     // Open the Slide Deck by ID

     if (documentId) {

       presentation = SlidesApp.openById(documentId);

     } else {

       // Handle case where document ID is empty (optional: log error message)

       continue;

     }

      // Extract slides and add them to the slides array

     slides = slides.concat(presentation.getSlides());

   }

 }


 // Add all collected slides to the new presentation

 for (var i = 0; i < slides.length; i++) {

   newPresentation.appendSlide(slides[i]);

 }

}

  

The error:

  • Try as I might (and I’ve apwnr hours of debugging sessions on this with Google Gemini), I consistently get the following error:
    TypeError: SlidesApp.newPresentation is not a function


I believe this implies the Slides API is not connecting to the script, which is preventing it from running any of the Slides related functions (create, append etc.)


I’ve tried all of these suggestions:

  • Enabling the Google Slides API service in Apps Script, from Services | Add a Service

  • Trying to run the script as a Standalone and a Container-Bound script


But I just can’t seem to catch a break.


Any help would be really appreciated!


Web Dev

unread,
May 19, 2024, 6:40:34 AMMay 19
to Google Apps Script Community
Hi Marco. I think there's a problem with the line `var newPresentation = SlidesApp.newPresentation();`. Did you mean to use .create() method, instead? See SlidesApp.create().

DimuDesigns

unread,
May 20, 2024, 9:16:04 AMMay 20
to Google Apps Script Community
Classic case of AI hallucination (where a generative model produces inaccurate information and presents it as fact - oddly human behavior when you think about it). The method/function "newPresentation" does not exist in the SlidesApp service. As @Web Dev stated, use the create() method instead.

Ignacio Dominguez-Ramirez

unread,
May 23, 2024, 2:43:36 PMMay 23
to Google Apps Script Community
I third both Web Dev and DimuDesigns, seems the AI is dreaming lol. You can see all of the Slides API capabilities here: https://developers.google.com/slides/api/reference/rest but more specifically the section referenced by the both responses above can be found here: https://developers.google.com/slides/api/reference/rest/v1/presentations/create As you can see from the former link, there are really on three major actions you can take on presentations batchUpdate, create and get.
Reply all
Reply to author
Forward
0 new messages