Google Apps Script toast messages don't appear for anonymous editors

前端 未结 2 508
醉梦人生
醉梦人生 2020-12-11 12:52

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 s

相关标签:
2条回答
  • 2020-12-11 13:03

    As you can see in the documentation:

    Apps Script requires user authoritaztion to access private data from built-in Google Services or advanced Google services

    That means you can share your script with anyone, but they need to log in to use the script.

    0 讨论(0)
  • 2020-12-11 13:18
    • You want to display a message when the cells of Spreadsheet are edited by anonymous.
    • The Spreadsheet is publicly shared for anonymous users as the editor.

    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.

    Before you use this script, please prepare an image for displaying.

    Sample script:

    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();
    }
    
    • In this sample script, when the cell is edited, the prepared image is displayed and waited for 3 seconds, and then, the image is removed.

    Result:

    Note:

    • Of course, you can create an image for displaying with the script. But in this case, the process cost will become high. As the result, the time until the image is displayed becomes long. So I proposed to use the image which was created in advance.

    References:

    • toast()
    • Class Ui
    • Installable Triggers
    • insertImage()

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

    0 讨论(0)
提交回复
热议问题