簡體   English   中英

通過 Google Apps Scripts #2 發布 Google 電子表格

[英]Publish a Google Spreadsheet through Google Apps Scripts #2

我正在嘗試通過腳本代碼發布一個網絡應用程序。 我讀了這篇文章,但我無法讓它工作,也許情況略有不同。 我有一個復制電子表格的腳本:在腳本中,我想將電子表格的新副本發布為網絡應用程序,如果可能,檢索其公共 URL(任何人都應該能夠訪問它)。

這是我的代碼:

  // Make a copy of the spreadsheet
  var repliesFile = responseTemplate.makeCopy('risposte', newFolder);
  var repliesId = SpreadsheetApp.openById(repliesFile.getId());

  // pubblish the new copy as a web app
  Drive.Revisions.update({published: true, publishedOutsideDomain: true, publishAuto: true}, repliesId, 1);

  // of course, this doesn't work.. I need a way to get the web app public url of the new copy
  var webAppUrl = ScriptApp.getService().getUrl(); 

我收到 404 錯誤。 我究竟做錯了什么? Drive Api v.2 在腳本中啟用。 感謝你給與我的幫助!

  • 您要發布復制的電子表格。
  • 您想要檢索已發布電子表格的 URL。
  • 您想通過修改腳本來實現這一點。

如果我的理解是正確的,這個答案怎么樣? 請將此視為幾種可能的答案之一。

改裝要點:

  • 在您的腳本中,我認為repliesId不正確。 它是電子表格對象。 請使用repliesFile.getId()作為文件 ID。
  • 不幸的是,在當前階段,無法檢索到像https://docs.google.com/spreadsheets/d/e/2PACX-###/pubhtml這樣的 URL。 但是您可以將https://docs.google.com/spreadsheet/pub?key=### spreadsheetId ###作為已發布電子表格的 URL。

修改后的腳本:

當您的腳本被修改時,請進行如下修改。

從:
 Drive.Revisions.update({published: true, publishedOutsideDomain: true, publishAuto: true}, repliesId, 1);
到:
 var fileId = repliesFile.getId(); Drive.Revisions.update({published: true, publishedOutsideDomain: true, publishAuto: true}, fileId, 1); var url = "https://docs.google.com/spreadsheet/pub?key=" + fileId;
  • url可用作已發布電子表格的 URL。

筆記:

  • 在這種情況下,請在高級 Google 服務中啟用 Drive API。

參考:

如果我誤解了您的問題並且這不是您想要的結果,我深表歉意。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM