Let Me Tink About It
Let Me Tink About It

Reputation: 16112

How to publish a Google Slides presentation from Google Apps Script?

I have built a Google Slides presentation using Google Apps Script.

var docId = DriveApp.getFileById(templateId).makeCopy().getId();
var newDoc = DriveApp.getFileById(docId).setName(newDocName);
var newDocUrl = newDoc.getUrl(); // This gets the URL of the editing view. I want the presentation view.

How do I publish it then get the URL of the published presentation?

Here are the docs. I'm looking for something like:

var publishedNewDoc = newDoc.publish();
var newDocPublishedUrl = publishedNewDoc.getPublishedUrl();

Upvotes: 2

Views: 906

Answers (1)

Tanaike
Tanaike

Reputation: 201388

  • You want to publish Google Slides using a script.
  • You want to retrieve the published URL.
  • You want to achieve this using Google Apps Script.

If my understanding is correct, how about this answer?

Publishing Google Slides:

In order to publish the Google Docs, you can use the method of Revisions: update in Drive API. About this, you can see a sample script as one of several answers.

Sample script:

Before you use this script, please enable Drive API at Advanced Google services.

var slidesId = "###"; // Please set this.
Drive.Revisions.update({published: true, publishedOutsideDomain: true, publishAuto: true}, slidesId, 1);

Retrieving published URL:

When you publish manually the Google Slides to the web, you can see the URL like https://docs.google.com/presentation/d/e/2PACX-###/pub. Unfortunately, in the current stage, this URL cannot be retrieved. So as a workaround, the published URL can be retrieved using the file ID. The published URL with the file id for Google Slides is as follows.

https://docs.google.com/presentation/d/### file ID ###/pub
  • If you want to use the query parameter, please set it above URL.
  • There are no methods for directly creating above URL, so please create it using a script.

References:

If I misunderstood your question and this was not the result you want, I apologize.

Upvotes: 5

Related Questions