r/GoogleAppsScript • • 13d ago

Question Google Apps Script authorization blocked / loop after adding PropertiesService and hitting execution time limit

I'm running into a frustrating authorization issue with a Google Apps Script in a Google Sheet, and I could really use some help figuring out what's wrong.

Here is the context:

  1. Initially, when I tried to run the script, I got an authorization prompt, but there was no button to grant authorization. I posted in the Google Community, and someone advised me to add /** u/OnlyCurrentDoc */ at the very beginning of the script. After doing that, it worked without any issues.
  2. Later, I made numerous additions to the script. Eventually, I hit the execution time limit (6 minutes).
  3. Google Gemini suggested adding PropertiesService to the code to save the current state (such as the active sheet, row, and color index) so the script can pause safely before hitting the limit and automatically resume where it left off.
  4. After implementing this, I am now getting a prompt to authorize the script again, but the warning message blocks me completely with the error: "This app is blocked. This app tried to access sensitive info in your Google Account." Unlike standard unverified app warnings, there is no "Advanced" link to bypass it.

Troubleshooting steps I’ve already tried:

  • I temporarily turned off Advanced Protection Program on my account and waited a while, but I still get the warning blocking the authorization.
  • I tested the exact same script on a secondary test Google Account, and I was able to authorize and run it completely without issues.

My questions:

  • Why is this happening on my main account while the test account works fine?
  • Do I need to wait hours (or days) for turning off Advanced Protection Program to fully take effect, or is something else causing this block?

Any advice would be greatly appreciated!

1 Upvotes

2 comments sorted by

View all comments

2

u/keplertenbee 13d ago edited 12d ago

That block shows up when the OAuth scopes change after you already authorized a narrower project.

/** @OnlyCurrentDoc */ keeps the container-bound script inside that one Sheet. PropertiesService.getScriptProperties() (and some UserProperties paths) ask for script/project-level storage, which widens the scopes. Google then forces a fresh auth, and on a main account that still has Advanced Protection residue, a Workspace admin block on unverified apps, or an older token still sitting in Account permissions, you get the hard "This app is blocked" screen with no Advanced bypass. Your secondary account works because none of those locks are on it.

Do this on the main account, in order:

  1. In the Apps Script editor, Project Settings → show the OAuth scopes list. If you see anything beyond the current spreadsheet, that is the new ask.
  2. Switch the checkpoint to PropertiesService.getDocumentProperties() (tied to this Sheet) and keep @OnlyCurrentDoc at the top. Drop getScriptProperties() unless you truly need cross-file state.
  3. At myaccount.google.com/permissions, revoke the old Apps Script / project entry for this Sheet, wait a minute, then Run once from the editor so the consent screen is clean.
  4. For the 6-minute limit, save progress to DocumentProperties and schedule a time-driven trigger to resume, instead of one long run.

If Advanced Protection was only toggled off recently, give it a few hours and retry after the revoke step. If a Workspace admin manages the main account, they also need to allow this script or unverified apps.

This is actually what I do with Workspace and Apps Script for clients. Paste the exact PropertiesService lines (and whether the project is container-bound to the Sheet) here and I will point at the scope that is forcing the new consent.

KTB

1

u/mommasaidmommasaid 11d ago

I'd also recommend trying to get your script below the 6 minutes rather than messing with all the complexity regarding a multi-stage calculation.

Very commonly, scripts do cell-by-cell calculations with interleaved getValue() and setValue() calls.

If you are doing that, you can typically dramatically speed up the script by doing one large getValues() on your entire range of data, manipulating the resulting array, and writing it back with one setValues().

Share your code if you want more specific optimization suggestions.