M
M
maksam072020-02-21 17:05:25
Google Sheets
maksam07, 2020-02-21 17:05:25

Why the error pops up: You are not allowed to call the user SpreadsheetApp.openById. Required permissions..?

Good afternoon. I write scripts for tables. Everything works well if the functions are run from the newly created menu at the top:

function onOpen(){
  var spreadsheet = SpreadsheetApp.getActive();
  var menuItems = [
    { name: 'Обновить', functionName: 'Refresh' },
    { name: 'Обновить (интервал 5 сек.)', functionName: 'Refresh5sec' },
    { name: 'Тест (не нажимать)', functionName: 'getSecondary' },
  ];
  spreadsheet.addMenu( 'СКРИПТЫ', menuItems );
}

But if you use a cell editing trigger and run a function from it, then an error pops up in the console:
function onEdit( e ){
  var range = e.range;
  if( range.getA1Notation() == 'F3' ){
    getSecondary();
  }
}

Mistake:
Скрипт Google Apps: Exception: Вам не разрешено вызывать пользователя SpreadsheetApp.openById. Необходимые разрешения: https://www.googleapis.com/auth/spreadsheets.


Moreover, when I first called the function through the menu, I got a window where Google asked me to grant permissions, which I did. And after that, the functions, through the menu, began to work perfectly. But why doesn't it work when editing a cell? Despite the fact that I already gave the same rights.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
maksam07, 2020-02-22
@maksam07

The option of creating an installable (full-fledged, uneasy) trigger for editing helped and slightly changed the name of the function so that it does not conflict with the trigger attached to this function (onEdit)

function onEditInstall( e ){
  var range = e.range;
  if( range.getA1Notation() == 'F3' ){
    getSecondary();
  }
}
Thanks to Oleg and Alexander Ivanov for the hint

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question