[英]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 在腳本中啟用。 感謝你給與我的幫助!
如果我的理解是正確的,這個答案怎么樣? 請將此視為幾種可能的答案之一。
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。如果我誤解了您的問題並且這不是您想要的結果,我深表歉意。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.