1

为了在自定义 HTML 对话框中使用 google.script.run 诊断问题,我在我的个人帐户和 G Suite 帐户中运行了 Google 的示例脚本和对话框的 HTML 代码。这是谷歌的例子:https ://developers.google.com/apps-script/guides/html/communication 。代码如下所示。

  • 在我的个人帐户中,代码运行良好。弹出自定义 HTML 对话框,函数 doSomething 创建日志输出。

  • 在我的 G Suite 帐户中,doSomething 函数根本没有运行。我尝试使用设置、作为附加组件进行测试、发布到网络等等,但我无法让 Google 的示例代码正常工作。我花了一个小时与 Google 支持人员进行聊天。

我的猜测:我的 G Suite 帐户中缺少一些授权和/或设置步骤。请帮忙!我是 G Suite AddOn Marketplace 的新手,希望能提供非常具体的后续步骤说明。在提交审核之前,我想确保我的真实脚本可以在我的 G Suite 帐户上运行。我想使用自定义对话框,以便可以在多个字段中收集用户输入。

这是一个文档链接,其中包含我的授权和执行窗口的屏幕截图。我没有在我的 G Suite 帐户中收到预期的“此应用未验证”警告。https://docs.google.com/document/d/1IiXmPE7zB1E-s_Uzzhmc0ggOCkz3qqcy1cqZrezkgSg/edit?usp=sharing

这是谷歌脚本代码:

 // code.gs
 // Use this code for Google Docs, Slides, Forms, or Sheets.
 function onOpen() {
 SpreadsheetApp.getUi() // Or DocumentApp or SlidesApp or FormApp.
     .createMenu('Dialog')
  .addItem('Open', 'openDialog')
  .addToUi();
}

function openDialog() {
  var html = HtmlService.createHtmlOutputFromFile('Index');
  SpreadsheetApp.getUi() // Or DocumentApp or SlidesApp or FormApp.
    .showModalDialog(html, 'Dialog title');
}

function doSomething(){   // I added from second step of example
   var ss = SpreadsheetApp.getActive(); 
   var sheet = ss.getSheetByName('Sheet1');  
   var cell1 = sheet.getRange("A1");
   cell1.setValue("did something");
   Logger.log("did something")
};

这是文件 Index.html 的 HTML 代码:

<!DOCTYPE html>"
   <html>
      <head>
        <base target="_top">
        </head>
        <body>
         Hello, World!

     <script>
     google.script.run.doSomething();
     </script>

        <input type="button" value="Close"
            onclick="google.script.host.close()" />
      </body>
    </html>

类似问题来自:Google Apps Script - HTML service not working normal only on G-suite accounts

4

1 回答 1

0

Did your script created in your personal or your GSuite accout? Please consider that Google Chrome capture as global log in, the account (email) that you use to do the first log in. Google don't mind if from this logged account you logged in others accounts: Google still continuing considering as global loggin the first one account you logged in. In this way, try to do the first log in with your GSuite accout; I hope this will solve the issue and you can run from all your accounts.

(thanks for Hujie Wang's replied to question/60438751/ : that helped me undertood this issue and solve it for my project)

于 2020-11-02T23:12:35.533 回答