Reputation: 79
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!
Upvotes: 1
Views: 569
Reputation: 201378
If my understanding is correct, how about this answer?
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.
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
can be used as the URL of the published Spreadsheet.Upvotes: 3