删除Google表格上脚本所需的授权 [英] Remove authorisation required for script on Google sheets

查看:108
本文介绍了删除Google表格上脚本所需的授权的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于脚本功能均需要授权,因此我在为用户创建的Google表格上运行了一些绑定脚本.

I run a few bound scripts on Google Sheets I create for users, due to the script functions all require authorisation.

脚本从电子表格本身上插入的按钮运行.我想删除授权过程,以便匿名用户可以运行脚本-我曾尝试将脚本作为Web应用程序部署,但这没有用.

The scripts run from buttons inserted on the spreadsheet itself. I want to remove the authorisation procces so that anonymous users can run the script - I have tried deploying the script as a web app but this hasn't worked.

有人知道如何创建这些脚本,以便任何人都可以运行该脚本而不必通过Google帐户授权吗?

Has anyone got any ideas what I can do to create these scripts so that anyone can run the script without having to authorise through a Google account please?

非常感谢

P.S.不要建议我让所有用户都创建Google帐户,因为那将不会发生! :-)

P.S. don't suggest that I get all users to create Google accounts as that just isn't going to happen! :-)

推荐答案

  • 您要使未登录Google的用户通过单击电子表格上的按钮来运行电子表格的容器绑定脚本.
  • 您要使用户在未经授权的情况下运行脚本.
  • 如果我的理解是正确的,那么这个答案如何?请认为这只是几个可能的答案之一.

    If my understanding is correct, how about this answer? Please think of this as just one of several possible answers.

    不幸的是,在当前阶段,未登录Google的用户无法通过单击电子表格上的按钮来运行脚本.您的问题中已经提到了这一点.这种情况与自定义菜单相同.

    Unfortunately, in the current stage, users as anyone who don't login to Google cannot run the script by the clicking a button put on Spreadsheet. This has already mentioned in your question. This situation is the same with the custom menu.

    所以在这个答案中,我想提出一个解决方法.

    So in this answer, I would like to propose a workaround.

    在此替代方法中,将使用OnEdit事件触发器.根据您的问题,我认为您的脚本可能包含要求授权范围的方法.因此,这里,OnEdit事件触发器用作可安装触发器.当脚本由OnEdit事件触发器运行时,该脚本将作为所有者运行.当您将OnEdit事件触发器安装为可安装触发器时,将运行授权过程.因此,当用户使用此脚本时,不需要授权过程.

    In this workaround, the OnEdit event trigger is used. From your question, I thought that your script might include the methods for requiring to authorize the scopes. So here, the OnEdit event trigger is used as the installable trigger. When the script is run by the OnEdit event trigger, the script is run as the owner. When you install the OnEdit event trigger as the installable trigger, the authorization process is run. So when users use this script, the authorization process is not required.

    为了使用此示例脚本,请执行以下流程.

    In order to use this sample script, please do the following flow.

    1. 通过将脚本包括在脚本编辑器中来复制并粘贴以下脚本.
    2. 将OnEdit事件触发器安装到installedOnEdit作为可安装触发器.
    3. 一个复选框用作执行脚本的按钮.为了执行脚本,作为测试用例,请在单元格"A1"中选中一个复选框.
    1. Copy and paste the following script by including your script to the script editor.
    2. Install the OnEdit event trigger to installedOnEdit as the installable trigger.
    3. A checkbox is used as the button for executing the script. In order to execute the script, as a test case, please put a checkbox to the cell "A1".

    示例脚本:

    function installedOnEdit(e) {
      var lock = LockService.getScriptLock();
      if (lock.tryLock(10000)) {
        var range = e.range;
        try {
          if (range.getA1Notation() == "A1" && e.value == "TRUE") {
    
    
            // Please put your script here.
    
    
          }
        } catch(err) {
          throw new Error(err)
        } finally {
          range.uncheck();
          lock.releaseLock();
        }
      }
    }
    

    • 在此脚本中,当您选中复选框时,将运行if语句中的脚本.脚本完成后,e.range.uncheck()不会选中该复选框.这样,该复选框将返回待机状态.
    • 通过LockService,脚本的独占处理得以运行.
    • 如果脚本的处理时间超过10秒,请修改lock.tryLock(10000).
      • In this script, when you check the checkbox, the script in the if statement is run. And when the script is finished, the checkbox is unchecked by e.range.uncheck(). By this, the checkbox is back to standby.
      • By LockService, the exclusive processing of the script is run.
      • If the process time of your script is over 10 seconds, please modify lock.tryLock(10000).
        • Installable Triggers
        • Event Objects
        • Lock Service

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

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

        这篇关于删除Google表格上脚本所需的授权的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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