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.Usage:
Please do the following flow.
1. Create new project of Google Apps Script.
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.
2. Prepare script.
Please copy and paste the following script (Google Apps Script) to the script editor. This script is for the Web Apps.
fileName.txtinhttps://script.google.com/macros/s/APP_ID/exec/fileName.txt, please usepathInfo.eofdoGet(e)by accessing withhttps://script.google.com/macros/s/APP_ID/exec/fileName.txt, you can retrieve{"contextPath":"","contentLength":-1,"parameter":{},"parameters":{},"queryString":"","pathInfo":"fileName.txt"}.3. Deploy Web Apps.
https://www.googleapis.com/auth/drive.readonlyandhttps://www.googleapis.com/auth/driveto the access token. These scopes are required to access to Web Apps.https://script.google.com/macros/s/###/exec.4. Run the function using Web Apps.
Please access to
https://script.google.com/macros/s/###/exec/filename.txtusing your browser. By this, a text file is downloaded.Note:
References:
Updated on February 14, 2023
In the current stage, it seems that
pathInfocan be used with the access token. It supposes that the following sample script is used.When you log in to your Google account and you access
https://script.google.com/macros/s/###/exec/sample.txtwith your browser,{"contextPath":"","parameter":{},"pathInfo":"sample.txt","contentLength":-1,"parameters":{},"queryString":""}can be seen.In this case, when you access it without logging in Google account, even when Web Apps is deployed as
Execute as: MeandWho has access to the app: Anyone, the log in screen is opened. Please be careful about this.And, if you want to access with
https://script.google.com/macros/s/###/exec/sample.txtusing a script, please request it by including the access token. The sample curl command is as follows. In this case, the access token can be used as the query parameter. Please include one of the scopes of Drive API in the access token.By this, the following result is returned.