匿名编辑者不会显示 Google Apps Script toast 消息 [英] Google Apps Script toast messages don't appear for anonymous editors

查看:18
本文介绍了匿名编辑者不会显示 Google Apps Script toast 消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在可安装的 onEdit 触发器函数中调用 toast 消息,每当进行编辑时,该函数都会在 Google 表格界面中显示一条消息.对于登录其 Google 帐户的用户,该消息会按预期显示,但当编辑者为匿名时,该消息不会显示在界面中.

I have a call to a toast message within an installable onEdit trigger function that displays a message in the Google Sheets interface whenever an edit is made. The message shows up as expected for users that are logged in to their Google account, but it doesn't show up in the interface when the editor is anonymous.

我有一个启用了匿名编辑的表格文件(知道链接的人").有一个独立的 Google Apps 脚本项目已经安装了一个可安装的 onEdit 触发器.该函数中的所有内容都对匿名用户和登录用户成功执行,但 toast 消息除外,该消息仅对登录用户显示.

I have a Sheets file that has anonymous editing enabled ("Anyone with the link"). There is a standalone Google Apps Script project that has installed an installable onEdit trigger. Everything in the function executes successfully for both anonymous and logged in users except for the toast message, which only shows up for logged in users.

可安装的 onEdit 触发器设置为执行 showMessage 函数.

The installable onEdit trigger is set up to execute the showMessage function.

触发器安装方式:

ScriptApp.newTrigger('showMessage').forSpreadsheet('thefileid').onEdit().create();

showMessage 函数:

function showMessage(e) {

    var msg = 'Some msg';
    var title = 'Some title';
    var file = e.source;
    var activeSheet = file.getActiveSheet();
    file.toast(msg, title);

    // do other things

}

Toast 消息为登录用户显示,而不是匿名用户.函数中的其他事物"按每个人的预期工作.我正在寻找一种向匿名用户显示该消息的方法(或寻找某种方式向他们传达自动消息).脚本项目是独立的而不是容器绑定的,所以我不能使用 Ui 类来通知他们.容器绑定脚本不是一种选择,因为此脚本的大小很大并且可以在多个文件上运行.

The toast message appears for logged in users, not anonymous ones. The 'other things' in the function work as expected for everyone. I'm looking for a way to show anonymous users that message (or looking for some way to communicate automated messages to them). The script project is standalone and not container-bound, so I can't use the Ui class to notify them. Container bound scripts are not an option, as this script is substantial in size and gets run on multiple files.

推荐答案

  • 您希望在电子表格的单元格被匿名编辑时显示一条消息.
  • 电子表格以编辑者身份公开共享给匿名用户.
  • 如果我的理解是正确的,这个答案怎么样?不幸的是,即使使用已安装的 OnEdit 事件触发器,在编辑匿名用户时,也无法使用 toast() 和 Class Ui.因此,作为几种解决方法之一,我想建议使用图像.幸运的是,insertImage() 可以用于这种情况.所以我正在使用这个解决方法.请将此视为多个答案之一.

    If my understanding is correct, how about this answer? Unfortunately, even when the installed OnEdit event trigger is used, when anonymous users are edited, toast() and Class Ui cannot be used. So as one of several workaround, I would like to propose to use the images. Fortunately, insertImage() can be used for this situation. So I'm using this workaround. Please think of this as just one of several answers.

    在使用此脚本之前,请准备好要显示的图像.

    在使用此脚本之前,请设置图像的文件 ID.并请安装showMessage()函数的OnEdit事件触发器.

    Before you use this script, please set the file ID of the image. And please install the OnEdit event trigger for the function of showMessage().

    function showMessage(e) {
      var fileId = "###"; // Please set the file ID of the image.
    
      var sheet = e.source.getActiveSheet();
      var blob = DriveApp.getFileById(fileId).getBlob();
      var image = sheet.insertImage(blob, 2, 3);
      Utilities.sleep(3000);
      image.remove();
    }
    

    • 在此示例脚本中,当编辑单元格时,显示准备好的图像并等待 3 秒,然后移除图像.
      • 当然,您可以创建与脚本一起显示的图像.但在这种情况下,工艺成本会变得很高.结果,直到显示图像的时间变长.所以我建议使用预先创建的图像.

      如果我误解了您的问题并且这不是您想要的方向,我深表歉意.

      If I misunderstood your question and this was not the direction you want, I apologize.

      这篇关于匿名编辑者不会显示 Google Apps Script toast 消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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