DriveApp and GmailApp Services not working simultaneously in Google Apps Script

36 views
Skip to first unread message

Kuldeep Singh

unread,
Dec 20, 2024, 8:27:26 AM12/20/24
to Google Apps Script Community
0

I'm encountering an issue with Google Apps Script when trying to use DriveApp and GmailApp together. Here's the situation:

  1. When I call DriveApp alone, it accesses folders without any issues.
  2. Similarly, when I call GmailApp alone, it works perfectly and retrieves emails as expected.
  3. However, when I try to use both DriveApp and GmailApp in the same script, I get the
    following error: "Exception: Permission required to access."

Code.gs

function test () { let folder = DriveApp.getFolderById(FolderID); let threads = GmailApp.search('is:starred') let sheet = SpreadsheetApp.openById(sheetID) console.log({ folder : folder, threads : threads, sheet : sheet }) }


When these two services are called together in the same script, it throws the error.

error: "Exception: Authorization is required to perfom that action test @code.gs.2"

Troubleshooting steps I’ve tried:

  • Checked the scopes in the project manifest file (appsscript.json) to ensure both Drive and Gmail APIs are included.
  • Verified that I’ve authorized the script fully for both services by login in prompt window and allow permission.
  • Tried separating the calls into different functions, but the issue persists when combined. What could be causing this, and how can I resolve it to use both services in the same script?
  • I have tried to create new project and write out the code from scratch but no luck
  • clear out cache memory login through different browser etc


Reply all
Reply to author
Forward
0 new messages