I am trying to publish a web app through the script code. I read this post but I can't make it work, maybe it's a slightly different situation. I have got a script that copies a spreadsheet: in the script, I want to publish the new copy of the spreadsheet as a web app and, if it's possibile, retrieve its public url (anyone should be able to access to it).
Here it is my code:
// 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();
I got an 404 error. What am I doing wrong? Drive Api v.2 is enabled in the script. Thanks for any help you can give me!
If my understanding is correct, how about this answer? Please think of this as just one of several possible answers.
repliesId
is not correct. It's the Spreadsheet object. Please use repliesFile.getId()
as the file ID.https://docs.google.com/spreadsheets/d/e/2PACX-###/pubhtml
cannot be retrieved. But you can https://docs.google.com/spreadsheet/pub?key=### spreadsheetId ###
as the URL of published Spreadsheet.When your script is modified, please modify as follows.
From: Drive.Revisions.update({published: true, publishedOutsideDomain: true, publishAuto: true}, repliesId, 1);
To:
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
can be used as the URL of the published Spreadsheet. If I misunderstood your question and this was not the result you want, I apologize.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.