ScriptApp.getService().getUrl()不返回实际的脚本URL [英] ScriptApp.getService().getUrl() doesn't return actual script URL

查看:81
本文介绍了ScriptApp.getService().getUrl()不返回实际的脚本URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的Google日历插件以部署ID AKfycbwFmqDJdIQDqGIMmujFEzwKZlrBKTPJaIitsHGfmqL72Ehm-YShfk3aJXLcJndQJJCU的形式发布,如下所示:

My Google Calendar addon is published as deployment id AKfycbwFmqDJdIQDqGIMmujFEzwKZlrBKTPJaIitsHGfmqL72Ehm-YShfk3aJXLcJndQJJCU as can be seen below:

但是在设置附加项设置"时,带有createSettingsUrlFunction并调用以下API的URL:

But when setting the add-on "Settings" URL with createSettingsUrlFunction and calling the following API:

ScriptApp.getService().getUrl()

返回的URL与部署ID URL不同: https://script.google.com/a/xxx.com/macros/s/AKfycbyy4AAzPl3smU-kdts89HQVaZiUFkFek-TyxwBi0FDsMHALscM/exec

The returned URL is different from the deployment ID URL: https://script.google.com/a/xxx.com/macros/s/AKfycbyy4AAzPl3smU-kdts89HQVaZiUFkFek-TyxwBi0FDsMHALscM/exec

此脚本ID AKfycbyy4AAzPl3smU-kdts89HQVaZiUFkFek-TyxwBi0FDsMHALscM是什么?我没有使用此ID进行任何部署.在以前的部署中,ScriptApp.getService().getUrl()始终返回相同的ID(脚本ID ==部署ID).

What is this script id AKfycbyy4AAzPl3smU-kdts89HQVaZiUFkFek-TyxwBi0FDsMHALscM? I don't have any deployment with this ID. With previous deployments, ScriptApp.getService().getUrl() always returned the same id (script id == deployment id).

推荐答案

脚本ID和部署ID不相同.

The Script ID and the Deployment ID aren't the same.

无论项目是作为附件还是作为Web应用程序部署或发布,脚本ID都是唯一的.另一方面,单个项目的部署ID可能与该项目的部署一样多.

The Script ID is unique, no matter if the project is deployed or published as add-on or as web application. By the other hand a single project could have as many Deployment ID as the project is deployed.

有两种类型的部署

  • 页眉部署
  • 版本化部署

AFAIK标头部署ID可能与脚本ID相同,但在归属部署中,部署ID将与脚本ID不同.

AFAIK the header deployment ID might be the same as the script id but on vesioned deployments the deployment ID will not be the same as the Script ID.

一种简单的解决方法,用于ScriptApp.getService().getUrl()在版本化的部署中返回错误的ID,实际上是一种解决方法:

One simple solution to ScriptApp.getService().getUrl() returning the wrong ID on versioned deployments, is actually a workaround:

硬编码要使用的ID,而不是使用ScriptApp.getService().getUrl().

解决方案可能是使用项目.deployments.list ,如果这对您的项目而言并不过分,因为它需要其他授权范围.

The solution might be to use projects.deployments.list, if that is not be overkilling for your project as it requires additional authorization scopes.

资源

相关

  • How to use versioned deployments when programmatically creating triggers?
  • ScriptApp.getService().getUrl() points to dev URL. How can I get it to point to exec production URL?
  • How to correctly display the "Current web app URL" in spreadsheet with `ScriptApp.getService().getUrl()`?

这篇关于ScriptApp.getService().getUrl()不返回实际的脚本URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆