Fixing Google Apps Script “PERMISSION_DENIED” Errors When Logged Into Multiple Accounts

-

Fixing Google Apps Script “PERMISSION_DENIED” Errors When Logged Into Multiple Accounts

Scenario

When you run a Google Apps Script add‑on (e.g., for Docs or Sheets) while signed into multiple Google accounts, you might see a PERMISSION_DENIED error. This happens because Apps Script uses the identity of the “user at the keyboard” to authorize access. Multi‑login can confuse the authorization flow.

Understanding Script Identity

According to Google’s documentation, the user identity that a script runs with—and the data it can access—depends on how the script is executed. For add‑ons bound to Google Docs, Sheets or Slides, the script runs with the credentials of the user interacting with the document. If you’re logged into multiple accounts in the same browser session, Apps Script might pick the wrong account or drop permissions entirely.

Steps to Fix PERMISSION_DENIED

  1. Use a Single Account Session: Sign out of other Google accounts or use a separate Chrome profile/incognito window for the account that owns the script.
  2. Revoke and Re‑authorize Permissions: If scripts were authorized under a different identity, revoke permissions and re‑authorize them:
    • Go to your Google Account’s Permissions page and remove the app’s access.
    • Run the script again; you’ll be prompted to grant permissions.
  3. Check Script Scopes: Ensure that your script only requests necessary scopes. Code that’s commented out can still trigger scope requests.
  4. Use @OnlyCurrentDoc for Add‑ons: If your add‑on should only access the current document, add this annotation at the top of the script to narrow its authorization scope.
  5. Test in V8 Runtime: Ensure your script is using the V8 engine and not the older Rhino engine. In the Apps Script editor, enable the V8 runtime under Run → Enable new runtime.

Additional Tips

  • For corporate domains, check whether an administrator needs to whitelist the add‑on.
  • Persistent PERMISSION_DENIED errors may indicate that the script is trying to access a service your account isn’t allowed to use.
  • Web apps and add‑ons with sensitive scopes may require Google verification.

Conclusion

Google Apps Script runs under the identity of the active user. Multi‑account sessions often cause authorization confusion. By using a single logged‑in account (or separate browser profiles), revoking old permissions, and ensuring your script requests only necessary scopes, you can resolve PERMISSION_DENIED errors and keep your add‑on running smoothly

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Recent comments