直接从Sheets将脚本作为Webapp部署 [英] Deploying Script as Webapp directly from Sheets
问题描述
是否完全可以直接从Google表格中将Google脚本部署为网络应用?
Is it, at all, possible to deploy a Google Scripts as web app directly from Google Sheets?
我正在尝试向Google表格添加自定义菜单,以便用户可以以编程方式将文件的脚本部署为网络应用.而且,似乎可以按照此GitHub存储库.
I am trying to add a custom menu to Google Sheets where the user can programmatically deploy the file's script as a web app. And it looks like it is possible to do so by following instructions from this GitHub repo.
但是出于明显的原因,我需要将projectId
设置为等于ScriptApp.getScriptId()
,以便在复制电子表格文件时,此变量被动态设置为等于该脚本的唯一ID.但是,当从自定义菜单执行saveAndDeployNewVersion()
时,我已经设置了(甚至从脚本本身内部),在从链中最后一个函数得到403错误之前,总是得到未定义的deploymentId
返回(
But for obvious reasons, I need to set projectId
to equal ScriptApp.getScriptId()
, so that when the Spreadsheet file is copied, this variable is dynamically set to equal to that script's unique id. However, when executing saveAndDeployNewVersion()
from the custom menu I've set up (and even from inside the script itself) I always get deploymentId
returned as undefined, before getting a 403 error from the final function in the chain (makeRequest_
).
还有其他方法吗,或者,您能指出在我自己的项目中实现此脚本时我做错了什么吗?
Is there any other approach, OR, can you point out what I'm doing wrong when implementing this script into my own project?
对 https://script.googleapis.com 的请求失败,返回了代码403.服务器截断响应:{ 错误":{代码":403,消息":"Apps Script API之前未在项目575477635395中使用或被禁用.通过vi ...启用它(使用MutantHttpExceptions选项检查完整响应)(第211行,文件代码")
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")
推荐答案
您需要
- 切换到标准GCP . li>
- 为该GCP启用应用程序脚本api
- Switch to standard GCP.
- Enable the apps script api for that GCP
另请参见相关答案.
这篇关于直接从Sheets将脚本作为Webapp部署的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!