Container-bound script deployed as Web App returns 404 (not found)

独自空忆成欢 提交于 2021-02-08 09:23:58

问题


I created a Spreadsheet-bound script with a single function:

function doGet() {
  Logger.log("test");
}

Then I deploy with: Execute as me, and Access - anyone, even anonymous.

However, going to published site fails with an error "Sorry, unable to open the file at this time." (or if accessed via curl - returns 404).

Exactly the same procedure works in standalone scripts. Is there a limitation or a gotcha about container-bound scripts?


回答1:


This may be a bug. The published endpoint URL returned from a container-bound script has a different structure than a endpoint URL for a standalone script.

Container-bound:

https://script.google.com/macros/u/1/s/<script-id>/exec

Standalone:

https://script.google.com/a/<google-apps-domain>/macros/s/<script-id>/exec

The solution was to use the url structure of a standalone script and replace <script-id> for the script that I need. This seems to have worked.




回答2:


Workaround

Container bound script URL have the following form:

https://script.google.com/macros/u/1/s/<script-id>/exec

Remove the u/1/ part:

https://script.google.com/macros/s/<script-id>/exec

Reference

  • Comment to Apps Script Wrong Web App URL From Script Editor (returns status code 404, with extra /u/1 in URL)

Explanation

At this time are two issues that looks to be related

  • Apps Script Wrong Web App URL From Script Editor (returns status code 404, with extra /u/1 in URL)
  • Container-bound script is not reachable (404) when deployed as Web App

It's worth to note, from https://developers.google.com/apps-script/guides/web,

Requirements for web apps

As script can be published as a web app if it meets these requirements:

  • It contains a doGet(e) or doPost(e) function.
  • The function returns an HTML service HtmlOutput object or a Content service TextOutput object.

As I understand the above, there is a problem with your script: it fails to return an object. Anyway, it should return

The script completed but did not return anything.

For a one line web app, try something like the following:

function doGet(e) {
  return ContentService.createTextOutput('Hello world!');
}

Regarding an explanation about why your code "works" on a stand-alone script but returns an error on a bounded-script, perhaps it's a glitch and it will be solved "by itself" soon. If it doesn't, checkout the Issue Tracker (follow the link on https://developers.google.com/apps-script/)



来源:https://stackoverflow.com/questions/47026444/container-bound-script-deployed-as-web-app-returns-404-not-found

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!