首页 > 解决方案 > 为什么“google.scrpt.run”不适用于 GAS 脚本中的 google 任务身份验证?

问题描述

google.script.run在 html 模板文件中使用它,它按我的预期工作得很好。
但在将 oauthScope "https://www.googleapis.com/auth/tasks" 添加到 appsscript.json 文件后它不起作用。

错误日志只是uncaught,所以无法进一步调查原因。
在此处输入图像描述

两者之间是否有任何关系或依赖关系?
我需要添加它来管理谷歌任务。

让我分享详细信息。

<!DOCTYPE html>
<html>
  <head>
    <base target="_top">
  </head>
  <body>
    <button onclick="showMessage()">showMessage</button>
    <script>
      function showMessage () {
        google.script.run.showMessage();
      }
    </script>
  </body>
</html>
function onEdit(e, spreadsheetId) {
  const htmlTmpl = HtmlService.createTemplateFromFile('someHtml')
  const html = htmlTmpl.evaluate().setWidth(900).setHeight(600)
  SpreadsheetApp.getUi().showModalDialog(html, 'title')
}

function showMessage () {
  Browser.msgBox('Hello world')
}
{
  "timeZone": "Asia/Tokyo",
  "dependencies": {
  },
  "webapp": {
    "access": "ANYONE",
    "executeAs": "USER_ACCESSING"
  },
  "exceptionLogging": "STACKDRIVER",
  "oauthScopes": [
                  "https://www.googleapis.com/auth/script.external_request", 
                  "https://www.googleapis.com/auth/spreadsheets.currentonly", 
                  "https://www.googleapis.com/auth/spreadsheets",
                  "https://www.googleapis.com/auth/script.container.ui"
                  ],
  "runtimeVersion": "V8"
function _onEdit(e) {
  // `-` is symbol for library.
  _.onEdit()
}
function showMessage () {
  //no logic here
}
  1. 将库脚本添加到容器绑定脚本(符号-在上面的示例中)
  2. 绑定_onEdit功能到可安装的编辑触发器。
  3. 打开 GSS
  4. 编辑一些单元格
  5. 显示对话框
  6. 按下showMessage按钮
  7. Hello world显示消息
  8. 将 oauthScope“https://www.googleapis.com/auth/tasks”添加到库中的 appsscript.json 文件中。
  9. 然后,再做3-6个流程
  10. 不显示消息并uncaught输出错误日志。

有人知道是什么原因吗?

谢谢,

标签: google-apps-scriptgoogle-sheetsgoogle-tasks

解决方案


推荐阅读