21

I wrote a google scripts editor addon, and published it to the google marketplace with private visibility (it is only visible to the users in my organization). I tested the addon with all types of permissions (installed for current user, enabled in current document, installed and enabled) in the script editor, and everything works as intended. However, after publishing the addon to the marketplace and installing it in a test spreadsheet, I keep getting this error: We're sorry, a server error occurred while reading from storage. Error code PERMISSION_DENIED. from the onOpen function.

I am setting these oauth scopes explicitly:

"oauthScopes": [
    "https://www.googleapis.com/auth/script.container.ui",
    "https://www.googleapis.com/auth/spreadsheets.currentonly",
    "https://www.googleapis.com/auth/script.scriptapp",
    "https://www.googleapis.com/auth/userinfo.email",
    "https://www.googleapis.com/auth/userinfo.profile"
  ]

And here is my onOpen trigger:

function onOpen(e: AppsScriptEvent) {
    if (e && e.authMode !== ScriptApp.AuthMode.NONE) {
        const ui = SpreadsheetApp.getUi();
        const menu = ui.createAddonMenu();
        menu.addItem("Add New Offering", "addNewOffering");
        menu.addSeparator();
        menu.addSubMenu(
            ui
                .createMenu("Settings")
                .addItem("Dashboard Name", "changeDashboardName")
                .addItem("Dashboard Start Cell", "changeDashboardStartCell")
        );
        menu.addToUi();
    }
}

What other type of permission am I missing here?

Rubén
  • 34,714
  • 9
  • 70
  • 166
Carlos
  • 405
  • 5
  • 12
  • 3
    Adding a similar issue from the issue tracker https://issuetracker.google.com/issues/150247026 and related question https://stackoverflow.com/questions/60438751/why-cant-i-call-a-server-function-from-the-sidebar-in-google-appscript-for-shee – Dave Sottimano Feb 28 '20 at 03:15
  • Suddenly started getting a very similar error (`... code UNAUTHENTICATED`) on a public (authentication-free) GAS web-app - but it went away after a simple manual re-run of the respective function from within the Apps Script editor – Janaka Bandara Mar 11 '20 at 01:22

4 Answers4

17

Disabling App Script V8 runtime fixed the issue for me when logged with multiple accounts...

I was developing an Add-on on my non-primary Google account so I was facing the error when calling server-side Google App Script functions from HTML Dialogs.

I hope that helps.

Oswald
  • 336
  • 2
  • 6
  • I looked all over for a solution to this problem and you fixed it for me. Thank you! – Chad French Jun 26 '20 at 11:33
  • Doesn't work for me. I am now getting a different error "Authorisation is required to perform that action." – Vikas Singhal Oct 08 '20 at 16:50
  • @VikasSinghal I think that in your case it might be a different issue, did you check that it works when you are logged in just one account? – Oswald Oct 09 '20 at 18:11
  • 2
    Disabling App Script V8 runtime works also in my case. Using a Library (running on v8) from a different user than the user who owns the library. When i run a script from the same user i can use V8. – jpp Feb 19 '21 at 16:17
  • Worked for me as well. Thank you! – dlrust Jun 16 '21 at 16:16
16

I ran into the same problem and it seems to be related with being signed into multiple google accounts on Chrome.

  • Laptop 1: Last night I was working on my Google App Script from my laptop which is only using one Google Account on Chrome.
  • Laptop 2: Today I'm trying to update my Google App Script using my other laptop which has multiple Google Account's signed-in.

When running the script from Laptop 2 I get an error:

We're sorry, a server error occurred while reading from storage. Error code PERMISSION_DENIED.`

I tried the script on Laptop 1 and everything was working fine. Next I opened an Incognito windows on Laptop 2 and signed into my single account and everything works.

Lee Taylor
  • 7,761
  • 16
  • 33
  • 49
2

I just faced with the issue. In my laptop there is few accounts and I developed not from the default one. After sharing the project to default account and accept the addon permissions by the default account the issue disappears.

1

The other answers are accurate that this problem occurs when logged in with multiple accounts.

I'd like to add that the order in which you log in will determine whether or not it occurs. If the first account you log in with (aka primary / default account) has permission to access the sheet and use its extension and you log in with other accounts afterwards, you will not have this problem.

A primary account without perms does cause problems, even if you signed in with an account with perms afterwards.

Benjamin
  • 45
  • 7