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

查看:87
本文介绍了匿名编辑者不会出现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秒钟,然后将图像删除.
      • 当然,您可以创建一个图像以与脚本一起显示.但是在这种情况下,处理成本将变高.结果,直到显示图像为止的时间变长.因此,我建议使用预先创建的图像.
      • toast()
      • Class Ui
      • Installable Triggers
      • insertImage()

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

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

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

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