Why "google.scrpt.run" does not work with google tasks auth in GAS script?

52 Views Asked by At

I'm using google.script.run in html template file, and it works well as I expected.
but it doesn't work after adding the oauthScope "https://www.googleapis.com/auth/tasks" to appsscript.json file.

Error log is just uncaught, so couldn't investigate the cause more.
enter image description here

Is there any relation or dependency between both?
I need to add this to manage google tasks.

Let me share the detail information.

  • there are 2 scripts
    ・container bound script for GSS
    ・library script referred by above container bound script.

  • html template in library script
    ・call google.script.run.registerSome() in html template.

<!DOCTYPE html>
<html>
  <head>
    <base target="_top">
  </head>
  <body>
    <button onclick="showMessage()">showMessage</button>
    <script>
      function showMessage () {
        google.script.run.showMessage();
      }
    </script>
  </body>
</html>
  • source code in library script
    ・show above html file as dialog on GSS Edit.
function onEdit(e, spreadsheetId) {
  const htmlTmpl = HtmlService.createTemplateFromFile('someHtml')
  const html = htmlTmpl.evaluate().setWidth(900).setHeight(600)
  SpreadsheetApp.getUi().showModalDialog(html, 'title')
}

function showMessage () {
  Browser.msgBox('Hello world')
}
  • appsscript.json in library
    ・before adding the "https://www.googleapis.com/auth/tasks"
{
  "timeZone": "Asia/Tokyo",
  "dependencies": {
  },
  "webapp": {
    "access": "ANYONE",
    "executeAs": "USER_ACCESSING"
  },
  "exceptionLogging": "STACKDRIVER",
  "oauthScopes": [
                  "https://www.googleapis.com/auth/script.external_request", 
                  "https://www.googleapis.com/auth/spreadsheets.currentonly", 
                  "https://www.googleapis.com/auth/spreadsheets",
                  "https://www.googleapis.com/auth/script.container.ui"
                  ],
  "runtimeVersion": "V8"
  • container bound script
    ・if this function is not declared, showMessage is not a function log is output on the browser console.
    ・_onEdit is bind to installable trigger onEdit.
    (to use some process asking the user for authorization)
function _onEdit(e) {
  // `-` is symbol for library.
  _.onEdit()
}
function showMessage () {
  //no logic here
}
  • replicating
  1. Add library script to container bound script(symbol is - in above sample)
  2. Bind _onEdit function to installable edit trigger.
  3. Open GSS
  4. Edit some cell
  5. Dialog is shown
  6. Press the showMessage button
  7. Hello world message is shown
  8. Adding the oauthScope "https://www.googleapis.com/auth/tasks" to appsscript.json file in the library.
  9. Then, do 3-6 process again
  10. Message is not shown and error log uncaught is output.

Does anybody know what the cause is?

Thanks,

0

There are 0 best solutions below