This error happens because Google has triggered a high-risk OAuth security block. DriveApp and UrlFetchApp require sensitive/restricted scopes, which Google automatically blocks if your script is linked to an unverified Google Cloud Platform (GCP) project or blocked by a Google Workspace domain policy.
Solution 1: Personal Gmail Accounts (@gmail.com)If your script is attached to a custom GCP project, Google blocks authorization unless your account is listed as a test user or you revert to the default project.
Add yourself as a Test User (if using a custom GCP project):
- Open the Google Cloud Console for your project
- Navigate to APIs & Services > OAuth consent screen.
- Scroll down to Test users and click + ADD USERS.
- Enter your Gmail address and click Save.
- Re-run your Apps Script function and authorize again.
Revert to Default GCP Project (easiest fix):- Open your Apps Script project.
- Click Project Settings (gear icon on the left menu).
- Under Google Cloud Platform (GCP) Project, click Change project.
- Set it back to the default project number if you manually linked an external GCP project without completing OAuth consent configuration.
Solution 2: Google Workspace Accounts (Work or School)Google Workspace administrators often enforce strict API security policies that block unverified apps requesting sensitive scopes.
Option A: Mark the App as Trusted (Workspace Admin required)
- Go to the Google Admin Console.
- Navigate to Security > Access and data control > API controls.
- Select Manage Third-Party App Access.
- Click Add App > OAuth App Name or Client ID.
- Paste your Apps Script's OAuth Client ID (found in your GCP Console or project settings) and set its status to Trusted.
Option B: Restrict Scopes in appsscript.json- In Apps Script, click Project Settings (gear icon) and check Show "appsscript.json" manifest file in editor
- Click appsscript.json in the file tree.
- Define explicit, minimal scopes in the oauthScopes array so Google doesn't automatically grant broad read/write access.ON
Courtesy of Gemini
G