Skip to content

Diagnostic reference

Exception: Access denied: DriveApp

Fix Exception: Access denied: DriveApp and No item with the given ID could be found in Apps Script: check sharing, effective user, file IDs, and OAuth scopes.

Updated December 6, 2026

Apps Script error

Exception: Access denied: DriveApp.

What it means

DriveApp throws Access denied or No item with the given ID could be found when the executing account (Session.getEffectiveUser()) lacks permission on the file or folder, when a full URL was passed instead of the ID, when the item was permanently deleted, or when a Workspace admin restricts sharing or external Drive access.

Related error messages

  • Exception: No item with the given ID could be found. Possibly because you have not edited this item or you do not have permission to access it.
  • Exception: Unexpected error while getting the method or property openById on object SpreadsheetApp.

Before and after

The code before and after the fix.

Problem 2 changed lines
function openClientFolder(folderUrlOrId) {
  // Passing a full URL, an ID shared only with another Google account, or a trashed ID fails.
  const folder = DriveApp.getFolderById(folderUrlOrId);
  Logger.log(folder.getName());
}
Fixed 6 changed lines
function openClientFolder(folderUrlOrId) {
  const match = String(folderUrlOrId).match(/[-\w]{25,}/);
  if (!match) throw new Error('Expected a Google Drive folder ID or URL.');
  const folder = DriveApp.getFolderById(match[0]);
  if (folder.isTrashed()) {
    throw new Error('Folder "' + folder.getName() + '" is in the trash.');
  }
  Logger.log(folder.getName());
}

How to fix it

  • Extract only the ID segment (between /d/ and /edit, or after /folders/) instead of passing the full Drive URL.
  • Log Session.getEffectiveUser().getEmail() and verify that exact account has Viewer or Editor access to the file or Shared Drive (installable triggers run as the trigger creator, not the current editor).
  • If the file is in a Shared Drive and you are using the Advanced Drive v3 service, add supportsAllDrives: true.
  • Check Overview > Project OAuth Scopes to confirm appsscript.json did not narrow scopes to drive.file or spreadsheets.currentonly.

Things to check

  • OAuth consent never overrides Google Drive sharing permissions; the executing account must still have Drive access to the file.
  • If a spreadsheet script uses /** @OnlyCurrentDoc */, SpreadsheetApp.openById() is blocked on other files even when your account owns them.

In the Apps Script editor

Catch errors like this before clicking Run.

myFunction (published as Error Checker for Google Apps Script on the Chrome Web Store) checks your code while you edit at script.google.com. Diagnostics, autocomplete, and rule-based quick fixes are free without an account, run in your browser, and request no Google Drive, Gmail, or Apps Script project OAuth scopes. Writing Apps Script with an AI coding agent? Connect the Apps Script MCP server to run the same static checks before pasting code.