每次拒绝在我自己的谷歌脚本中授予权限 [英] Deny granting permissions in my own google scripts everytime

查看:128
本文介绍了每次拒绝在我自己的谷歌脚本中授予权限的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

情况:

我已经让自己成为了一个输入工作时间的表格。在某些情况下,我必须输入一些链接,并将其命名为linkname的一部分。所以我决定创建一个自定义菜单,我只是在提示符中发布链接,脚本会删除所需的名称并将其输入到我的工作表中。

I have made my self a speadsheet to enter my working times. For some cases I have to enter some links and name them with part of the linkname. So I decided to create a custom menu where I simply post the link in a prompt and the script cuts out needed name and enters this to my sheet.

现在这只是在我的床单上跑。猜猜没有必要发布这样的东西:)

Now this is only running in my sheet. Guess there is no need to publish something like this :)

解决我的问题:

我有一个主要工作表并且每周复制一次,因为一张工作表只能解决一周。我的脚本使我授予它权限,以便它可以在当前工作表上执行上述操作。但每次我复制工作表(所以每周),我必须再次授予权限。期待我的谷歌帐户看到授予权限让我头疼,因为有大量的条目授予权限:(

I have a main workingsheet and copy this every week because one sheet only solves one week. My script causes me to grant permissions to it so it can do upper described actions on current sheet. But everytime I copy the sheet (so every week) I have to grand the permissions again. Looking to my google account seeing granted permissions giving me headache since there are planty of entries for granting permissions :(

问题:

有没有办法保持开发人员模式以防止此权限请求?

Is there a way to stay in kind of a developermode to prevent this permission requests?

为什么我必须拥有大权限到我自己的脚本?

Why do I have to grand permissions to my own script?

function onOpen(e) {
  var menu = SpreadsheetApp.getUi().createMenu('Custom Menu');
      menu.addItem('Add Ticket', 'addTicket');
      menu.addItem('Rename to KW XX', 'renameDocument');
      menu.addToUi();
}

function addTicket() {
  var ui     = SpreadsheetApp.getUi(); // Same variations.
  var sheet  = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
  var myCell = sheet.getActiveCell();
  var result = ui.prompt(
      'Add Ticket',
      'Please enter Ticket-link:',
      ui.ButtonSet.OK_CANCEL);

  // Process the user's response.
  var button = result.getSelectedButton();
  var link   = result.getResponseText();
  
  if (button == ui.Button.OK) {
    var n        = link.lastIndexOf('/');
    var linkName = link.substring(n+1);
    var vals     = myCell.setValue('=HYPERLINK("' + link +  '";"' + linkName + '")');
  } else if (button == ui.Button.CANCEL) {
    // User clicked "Cancel".
    ui.alert('You cancled adding ticket.');
  } else if (button == ui.Button.CLOSE) {
    // User clicked X in the title bar.
    ui.alert('You closed the dialog. No ticket was inserted.');
  }
}

function renameDocument() {
  eval(UrlFetchApp.fetch('https://momentjs.com/downloads/moment-with-locales.js').getContentText());
  var sheet = SpreadsheetApp.getActive();
  var doc   = DocumentApp.getActiveDocument();
  moment.locale('de');
  var kw    = moment().format('ww');
  var name  = sheet.getName();
  sheet.setName('KW ' + kw);
}

推荐答案

据我所知,工作表是指电子表格,即工作簿,文档和文件,因为在同一电子表格中的多个工作表上使用脚本不需要为每个工作表授权脚本一,因为你看到大量的条目授予权限

I understand that by "sheet" you mean spreadsheet, a.k.a. workbook, document and file, because using a script on several sheets that are on the same spreadsheet doesn't require to authorize the script for each one and because you are seeing a "plenty of entries for granting permissions"

另外我理解你的脚本是在一个绑定到电子表格的脚本项目上。

Also I understand that your script is on a script project bounded to an spreadsheet.

当我们制作电子表格的副本时,它将包含一个受限于它的脚本项目的副本。新电子表格及其有限项目因为它们是不同的文件而且Google的政策是脚本项目提供运行脚本的授权。

When we make a copy of an spreadsheet it will contain a copy to the script project bounded to it. The new spreadsheet and its bounded project as they are different files and the policy of Google is that the authorization to run a script is given by script project.

避免的方式拥有相同代码的许多副本并且必须授权它们中的每一个都是使用附加组件,这就是我投票将这个问题作为在所有电子表格中使用脚本

The way to avoid having a lot of copies of the same code code and have to authorize each of them is to use an add-on, that is the reason that I vote to close this question as duplicate of Use script in all spreadsheets

无论如何,答案

有没有办法保持开发人员模式以防止此权限请求?

Is there a way to stay in kind of a developermode to prevent this permission requests?

开发附加内容


为什么我必须拥有自己脚本的大权限?

Why do I have to grand permissions to my own script?

因为没有要求您向一个脚本授予权限被要求授予每个副本的许可。

Because you are not being asked to grant permissions to one script you are being asked to grant permission to each copy.

它值得注意的是,除了必须为每个副本授予权限的头痛之外,如果您对您的脚本进行了更改,它将仅在您编写它的脚本项目中,该更改将不会传播到副本。

It's worth to note that besides the headache of having to grant permissions to each copy, if you made a change to "your script" it will be only on the script project where you write it, that change will not be "propagated" to the copies.

另一种方法是使用库,但您仍然必须为使用库的每个脚本项目授予权限。

An alternative is to use a library but you still will have to grant permissions to each script project where you use the library.

关于在Google Chrome网上应用店发布的开发者费用,您可以在测试模式下运行您的插件,但是您必须将每个文件添加到相应的列表中,这对于处理大量文件。

Regarding the developer fee to publish on the Google Chrome Web Store, you could run your add-on on test mode but you will have to add each file to the corresponding list which is not very friendly to handle a large list of files.

这篇关于每次拒绝在我自己的谷歌脚本中授予权限的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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