如何从 Google Apps 脚本发布 Google 幻灯片演示文稿?

Mow*_*zer 2 google-apps-script google-slides google-slides-api

我使用 Google Apps 脚本构建了 Google 幻灯片演示文稿。

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.
Run Code Online (Sandbox Code Playgroud)

如何发布它并获取已发布演示文稿的 URL?

这是文档。我正在寻找类似的东西:

var publishedNewDoc = newDoc.publish();
var newDocPublishedUrl = publishedNewDoc.getPublishedUrl();
Run Code Online (Sandbox Code Playgroud)

Tan*_*ike 5

  • 您想要使用脚本发布 Google 幻灯片。
  • 您想要检索已发布的 URL。
  • 您希望使用 Google Apps 脚本来实现此目的。

如果我的理解是正确的,这个答案怎么样?

发布 Google 幻灯片:

为了发布Google Docs,您可以使用Drive API中的Revisions: update方法。关于这一点,您可以将示例脚本视为多个答案之一。

示例脚本:

在使用此脚本之前,请在高级 Google 服务中启用 Drive API。

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

检索已发布的 URL:

当您手动将 Google 幻灯片发布到网络时,您可以看到类似 的 URL https://docs.google.com/presentation/d/e/2PACX-###/pub。遗憾的是,现阶段无法检索该 URL。因此,作为解决方法,可以使用文件 ID 检索已发布的 URL。带有 Google 幻灯片文件 ID 的已发布 URL 如下。

https://docs.google.com/presentation/d/### file ID ###/pub
Run Code Online (Sandbox Code Playgroud)
  • 如果要使用查询参数,请将其设置在URL上方。
  • 没有直接创建上述 URL 的方法,因此请使用脚本创建。

参考:

如果我误解了你的问题并且这不是你想要的结果,我深表歉意。