I'm looking to make the url by adding a path which is something like this below in Google Apps Script:
https://script.google.com/macros/s/APP_ID/exec/fileName.txt
How can I achieve this for Web App service?
I'm looking to make the url by adding a path which is something like this below in Google Apps Script:
https://script.google.com/macros/s/APP_ID/exec/fileName.txt
How can I achieve this for Web App service?
I believe your goal as follows.
https://script.google.com/macros/s/APP_ID/exec/fileName.txt
.For this, how about this answer? I think that you can achieve your goal using Web Apps. As a sample case, I would like to explain about this using a sample script for downloading a text file, when an user accesses to https://script.google.com/macros/s/APP_ID/exec/fileName.txt
.
Please do the following flow.
Sample script of Web Apps is a Google Apps Script. So please create a project of Google Apps Script.
If you want to directly create it, please access to https://script.new/. In this case, if you are not logged in Google, the log in screen is opened. So please log in to Google. By this, the script editor of Google Apps Script is opened.
Please copy and paste the following script (Google Apps Script) to the script editor. This script is for the Web Apps.
function doGet(e) {
const path = e.pathInfo;
if (path == "filename.txt") {
const sampleTextData = "sample";
return ContentService.createTextOutput(sampleTextData).downloadAsFile(path);
}
return ContentService.createTextOutput("Wrong path.");
}
fileName.txt
in https://script.google.com/macros/s/APP_ID/exec/fileName.txt
, please use pathInfo
.
e
of doGet(e)
by accessing with https://script.google.com/macros/s/APP_ID/exec/fileName.txt
, you can retrieve {"contextPath":"","contentLength":-1,"parameter":{},"parameters":{},"queryString":"","pathInfo":"fileName.txt"}
.https://www.googleapis.com/auth/drive.readonly
and https://www.googleapis.com/auth/drive
to the access token. These scopes are required to access to Web Apps.https://script.google.com/macros/s/###/exec
.
Please access to https://script.google.com/macros/s/###/exec/filename.txt
using your browser. By this, a text file is downloaded.