为什么我不能从Google AppScript for Sheets的侧栏中调用服务器功能? [英] Why can't I call a server function from the sidebar in Google AppScript for Sheets?

查看:84
本文介绍了为什么我不能从Google AppScript for Sheets的侧栏中调用服务器功能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在从Google表格的html边栏中调用服务器端AppScript函数时遇到问题.

I'm having problems calling a server-side AppScript function from a html sidebar in Google Sheets.

我已经用下面的简单示例代码复制了我的问题.

I've replicated my issue with the simple example code below.

单击该按钮应在我的Code.gs脚本中调用alert并向用户显示警报.

Clicking the button should call alert in my Code.gs script and display an alert to the user.

单击按钮将显示错误:

We're sorry, a server error occurred while reading from storage. Error code PERMISSION_DENIED.

alert()的AppScript仪表板的执行"部分中没有条目,因此似乎从未调用过该函数?

There are no entries in the 'executions' section of the AppScript dashboard for alert(), so it seems like the function never even gets called?

function onOpen() {
  const ui = SpreadsheetApp.getUi();
  ui.createMenu('Matthew')
    .addItem('Show Sidebar', 'sidebar')
    .addToUi();
};

function sidebar() {
  const html = HtmlService.createHtmlOutputFromFile('test.html')
    .setTitle('Matthew Experiment')
    .setWidth(300);

  SpreadsheetApp.getUi().showSidebar(html);


}

function alert() {
  SpreadsheetApp.getUi().alert("alert!"); 
}

test.html(很好)

  <body>
    <div class="container">
       <button class="btn btn-success" onclick="doSomething()">Click Me!</button>
    </div>
    <script>
            function doSomething() {
          google.script.run.withFailureHandler(function(error) {
            console.log("error")
            console.log(error.message)
          }).withSuccessHandler(function(result) {
            console.log("done!")
          }).alert();
        }
    </script>
  </body>

我已经确认服务器端函数名正确地填充了客户端代码,只是在调用不起作用的函数.

I've confirmed that the client-code is getting properly inflated with server-side function names, it's just calling the function that doesn't work.

我的代码似乎与所有入门指南相同,但是我看不到其他人发布有关此问题的信息.希望这里的人比我对问题有更深入的了解.

My code seems to be the same as all of the getting started guides, but I don't see anyone else posting about this issue. Hoping someone here has deeper knowledge of the problem than I do.

我打开了一个私人窗口,它起作用了,所以我想,也许这是引起问题的扩展?但是,即使禁用所有扩展,也无法在主窗口中对其进行修复.我已经注销/登录了我的Google帐户,但是如果不打开私有浏览器窗口,仍然无法使其正常工作.

I opened a private window and it WORKED, so I thought, maybe this is an extension causing problems? But even disabling all extensions doesn't fix it in the main window. I've logged out/in to my google account but still can't get it to work without opening a private browser window.

这个问题在chrome/edge/firefox中都是一致的.

This problem is consistent across chrome/edge/firefox.

推荐答案

当全局登录用户与脚本所有者不同时,会发生这种情况.

This happens when the global logged in user is different from the owner of script.

注销所有的Google帐户,然后使用您用于创建脚本的帐户重新登录.这样就解决了这个问题.

Logout all your google account and then re-login with the account you used to created the script. This fixed the issue.

这篇关于为什么我不能从Google AppScript for Sheets的侧栏中调用服务器功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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