I have successfully created a client side script function that removes and reinstates all conditional formatting on a templated Sheet (to maintain a prescribed conditional formatting regime without locking cells). I have placed a call to this function in the sheets onOpen() event handler. When in the Script Editor I explicitly run the onOpen handler all works well. When I open the sheet and let the onOpen event run naturally I get an authentication error in response to the batchUpdate call that requests the Conditional Formatting changes:
Execution failed: Request is missing required authentication credential. Expected OAuth 2 access token, login cookie or other valid authentication credential.
1) Is there a logical explanation why the code does not fail authentication when I run the code explicitly from the Script Editor while it does fail in response to the onOpen event firing?
2) I have followed the OAuth 2 links and am a little overwhelmed, can anybody please direct me to a simple set of actions I need to take to allow me to make a client side script work with the Sheets object to which it is attached for all users? Is this a more difficult endeavour than I had anticipated?
Update: I got my code to work in script attached to a spreadsheet. An installable trigger was used to send API batch update requests of Conditional formatting - all good so far. I have a number of spreadsheets that I want to use the script, so I created a version of the script and added it as library to the first "new"spreadsheet. I had to authorize the API in that new sheet but once done the library trigger event fired at the appropriate point. However, despite the API batch update request being written in the context of an installable trigger (in the library file) execution again failed with the original error message:
"Execution failed: Request is missing required authentication credential. Expected OAuth 2 access token, login cookie or other valid authentication credential message.
Precisely the problem the Installable Trigger had solved previously.
What extra steps must I take to avoid this error in a library trigger please?