1

Regards,

I have found several questions regarding this error : "ScriptError: Authorisation is required to perform that action." but I can't find one that is about my issue.

What I am trying to do is call a function .gs file from .html file using google.script.run where both of the file is in Library. Referring to this answer, this answer and this bug report, I have created the "wrapper function" in the script that is using the library, but still failed to finish the execution.

Here's what I did :

.html in Library :

<html>

<head>
  <script>
    function onFailure(error) {
      console.log("ERROR: " + error);
    }

    function myfunc() {
      console.log("HERE");
      google.script.run.withFailureHandler(onFailure).callLibraryFunction('LibraryName.test', ['test123']);
    }
  </script>
</head>

<body>
  <button onclick="myfunc()">CLICK</button>
</body>

</html>

.gs in Library

function test(x){
  Logger.log(x);
}

.gs in script that is using the Library:

function callLibraryFunction(func, args) {
  var arr = func.split(".");

  var libName = arr[0];
  var libFunc = arr[1];

  args = args || [];

  return this[libName][libFunc].apply(this, args);
}

The console logs HERE but then it logs ERROR: ScriptError: Authorisation is required to perform that action. instead of the expected output, test123.

NOTE: The HTML is for custom modeless dialog box in Sheets and not for Web App.

I really hope someone can help me in this. Thank you in advance.

  • It does not look like you are you using a doGet() funciton in your library in order to access the HTML part of your library. – ziganotschka Nov 16 '20 at 08:29
  • Do I need ```doGet()``` ? Because I am not accessing it from the Web App URL and I am just using the HTML for custom dialog box in Sheets and not to redirect to a page. (I apologize that I forgot to mention this earlier, I'll update the question.) However, I did create an HtmlOutput from the HTML file [eg: ```.createOutputFromFile("htmlfile")```] and the HTML renders and run since the console logs ```HERE``` as I mentioned in the question. – Bismuth Habs Nov 16 '20 at 12:38
  • I see. Have you tried to run the script once manually from the script editor before doing so from the dialog? See [here](https://stackoverflow.com/questions/11421055/stopping-the-error-authorisation-is-required-to-perform-that-action-in-google). – ziganotschka Nov 16 '20 at 22:35
  • I did, and the console logs the expected output ```test123```. Which means it works when using it directly without the dialog. Also, all needed permission/scopes have been verified. I even tried making the scope more general by editing the manifest file, ```appscript.json```. But, still not luck. – Bismuth Habs Nov 17 '20 at 02:16
  • 1. Does your code library contain any trigger that might lead to your error? 2. What are the scopes you provided in in your manifest? 3. Have a look at [this](https://stackoverflow.com/questions/27673617/can-a-google-spreadsheet-apps-script-library-contain-a-user-dialog/27771542#27771542). – ziganotschka Nov 17 '20 at 06:21
  • 1. The trigger is when one of the Sheets custom menu is clicked. 2.The scopes I am using : ```https://www.googleapis.com/auth/documents``` ```https://www.googleapis.com/auth/drive``` ```https://www.googleapis.com/auth/drive.scripts``` ```https://www.googleapis.com/auth/gmail.compose``` ```https://www.googleapis.com/auth/script.container.ui``` ```https://www.googleapis.com/auth/script.external_request``` ```https://www.googleapis.com/auth/spreadsheets``` 3. Thank you. I have read it. Tried it. Unfortunately, no luck. – Bismuth Habs Nov 17 '20 at 07:40
  • Did you deplo the libarary as a new version after implementing any changes? Did you mnually edit the scopes in the manifest in both the library and the file? Can you show your COMPLETE code of both the library and the file where the library i used? Including the functions to show the dialog. – ziganotschka Nov 17 '20 at 15:27
  • Hi @BismuthHabs , have you found a solution? I'm experiencing exactly same issue (code from a library works when is run directly in script editor and produces the ScriptError when is run from withing a dialog). – Shrike Mar 19 '21 at 14:51
  • Hi @Shrike, yes I still have not found any solution for this. I ended up just use the code directly instead of using it as a library. If you do find any solution for this, do tell us. – Bismuth Habs Mar 26 '21 at 03:44

1 Answers1

0

You need to grant access of the library "LibraryName" as an authorized app in your Gmail account the same way how you grant access to the calling script. I guess you have called the method HtmlService.createHtmlOutputFromFile(...) in your library. This requires more authorization. You need to grant this. What you can do is create a temporary function in the library that has HtmlService.createHtmlOutputFromFile(..). Run it from the script editor and the authorization requirement window appears. Proceed in granting access...