I'm encountering an issue with Google Apps Script when trying to use DriveApp and GmailApp together. Here's the situation:
- When I call DriveApp alone, it accesses folders without any issues.
- Similarly, when I call GmailApp alone, it works perfectly and retrieves emails as expected.
- 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