For security reasons, Google Apps Script sandboxes your HTML Service (see restrictions documentation). In the case of Content Services, it redirects to a different domain every time it’s executed (see documentation). Because of this, you have two options: use Google Apps Script to execute as the visiting user and to get a static site hosting.
1. Using Google Apps Script
Instead of running the calls to the APIs in the front end, you can make functions in Google Apps Script and then call them using google.script.run
in the frontend. It will also simplify your code as all the OAuth is handled by Google Apps Script.
// Google Apps Script side
function doSomething() {
const ss = SpreadsheetApp.openByUrl('…')
// […]
return result
}
And to call it I’d use something like:
// Client side
function doWork() {
google.script.run
.withSuccessHandler(successCallback)
.doSomething() // Function name in the backend
}
Make sure to deploy the application with the option Execute as:
with the value User accessing the web app
so it’s not executed as you.
With this setup the user will be asked to give the required permissions before opening the page.
2. Use a web hosting
The second solution is to find a web hosting provider. Because you don’t seem to have a backend it can be for static pages (some are free). This will give you a stable URL and should work exactly the same as in your localhost.
References
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…