Google 电子表格应用程序脚本 - “您无权调用 UrlFetchApp.fetch”触发器:“在表单提交时”,sites.google.com 折旧后

问题描述 投票:0回答:1

这段代码已经运行了 15 年......谷歌每隔一段时间就会改变一些东西来搞砸它。

这一次,他们似乎删除/转换了 site.google.com 上的一个模板,我的电子表格表单正在使用该模板来生成电子邮件(我抓取 HTML,替换一些关键字段,然后发送电子邮件)。当用户在电子表格表单上点击“提交”时,触发器将调用脚本。

获取 HTML 模板的旧代码如下所示:

 var site = SitesApp.getSiteByUrl(<url>);
 var page = site.getChildByName('receipt');
 var content = page.getHtmlContent();

我访问“sites.google.com”,它说它删除了我所有的旧表单并将它们转换为新表单(所有转换都搞砸了,但是,嘿,这是我们的 Google 霸主)。我发布了它转换的内容并收到有关权限的错误,并且我看到所有这些“SitesApp”例程都被贬值了,所以现在尝试:

  var response = UrlFetchApp.fetch(<new URL>);
  var content = response.getContentText();

...并收到错误:“异常:您无权调用 UrlFetchApp.fetch。所需权限:https://www.googleapis.com/auth/script.external_request”

我的项目已经显示了该权限,但我遵循一些公开 JSON 脚本的规则,在其中我明确了 OAuth 范围:

{
  "oauthScopes": [
  "https://www.googleapis.com/auth/script.external_request",
  "https://www.googleapis.com/auth/drive",
  "https://www.googleapis.com/auth/script.send_mail",
  "https://www.googleapis.com/auth/userinfo.email",
  "https://www.googleapis.com/auth/spreadsheets",
  "https://www.googleapis.com/auth/calendar"
  ],
  "timeZone": "America/Adak",
  "dependencies": {},
  "exceptionLogging": "STACKDRIVER",
  "runtimeVersion": "V8",
}

但是,仍然出现错误。我看到其他人也有类似的错误,但只有当他们的触发器是隐式的时,我的触发器才会被显式调用。

如上所述,在将新模板保存在sites.google.com 并指向sites... 上的新模板后,我将代码更改为使用 UrlFetchApp.fetch,显式定义了 appscript.json。我还尝试过将 URL 放在公开网站上。

google-apps-script google-sheets google-oauth google-forms google-sites
1个回答
0
投票

需要删除并重新添加触发器。

© www.soinside.com 2019 - 2024. All rights reserved.