直接从表格将脚本部署为 Webapp

Deploying Script as Webapp directly from Sheets

是否可以直接从 Google 表格将 Google 脚本部署为 Web 应用程序?

我正在尝试向 Google 表格添加自定义菜单,用户可以在其中以编程方式将文件的脚本部署为 Web 应用程序。看起来可以按照 this GitHub repo.

的说明进行操作

但出于显而易见的原因,我需要将 projectId 设置为等于 ScriptApp.getScriptId(),以便在复制电子表格文件时,此变量动态设置为等于该脚本的唯一 ID。但是,当从我设置的自定义菜单(甚至从脚本本身内部)执行 saveAndDeployNewVersion() 时,我总是得到 deploymentId 作为未定义返回,然后从最终函数中得到 403 错误链条 (makeRequest_).

有没有其他方法,或者,您能指出我在将此脚本实施到我自己的项目中时做错了什么吗?

Request failed for https://script.googleapis.com returned code 403. Truncated server response: { "error": { "code": 403, "message": "Apps Script API has not been used in project 575477635395 before or it is disabled. Enable it by vi... (use muteHttpExceptions option to examine full response) (line 211, file "Code")

你需要

  1. Switch to standard GCP.
  2. Enable the apps script api for that GCP

另见