The code will successfully return the folder name that contains the spreadsheet in the execution log, but when calling the function in Sheets, I get an error (below).

After updating the json file, drive will pop-up a request for access which I grant but the error persists.

*****Error:

You do not have permission to call DriveApp.getFileById. 
Required permissions: (https://www.googleapis.com/auth/drive.readonly || 
https://www.googleapis.com/auth/drive) (line 4).

*****Code.gs:

function getFolder2() {
`  `const ss = SpreadsheetApp.getActive();//Logger outputs the name of this spreadsheet folder
`  `const id = ss.getId();
`  `const file = DriveApp.getFileById(ss.getId);
`  `const f = file.getParents().next()
`  `Logger.log(f.getName())
}

*****appsscript.json:
{
`  `"timeZone": "Pacific/Honolulu",
`  `"exceptionLogging": "STACKDRIVER",
`  `"oauthScopes": [
`    `"https://www.googleapis.com/auth/drive",
`    `"https://www.googleapis.com/auth/drive.readonly",
`    `"https://www.googleapis.com/auth/spreadsheets",
`    `"https://www.googleapis.com/auth/spreadsheets.readonly"
`  `]
}

I tried multiple methods of the code. Changed the folder locations to include My Drive and Shared Drives. Ensured login was correct.

Expecting the folder name to populate in the cell when function is called.

0

There are 0 best solutions below