0
votes

The following line of codes work in ScriptA but not in ScriptB:

var folder = DriveApp.getFolderById(folderId);

The oAuth is the same in both script files' appsscript.json:

...
"oauthScopes": [
"https://www.googleapis.com/auth/spreadsheets.readonly",
"https://www.googleapis.com/auth/spreadsheets",
"https://www.googleapis.com/auth/drive.readonly",
"https://www.googleapis.com/auth/drive",
"https://www.googleapis.com/auth/script.scriptapp",
"https://www.googleapis.com/auth/script.external_request"
],
...

What am I missing?

1
Is the script you are using deployed as an add-on? @EdmundToale13
Does this answer your question? stackoverflow.com/questions/64079595/…TheMaster
This can be solved by approving Google Drive API and Drive API in the script file by accessing the menu Resources --> Advanced Google Services..., and then enable the Drive API, and then at the bottom click the link to Google Cloud Platform API Dashboard and enable both Google Drive API and Drive API. As @TheMaster has pointed out, the method of duplicating to a new spreadsheet works but is not ideal if you want to preserve the same FileId stackoverflow.com/questions/64079595/…Edmund To
@EdmundTo Consider adding it as a answerTheMaster
I'm not allowed to add an answer, not sure why. If you can maybe you can add it and I can accept it? @TheMasterEdmund To

1 Answers

2
votes

This can be solved by activating the Google Drive API Advanced Services in the script file by accessing the menu Resources > Advanced Google Services..., and then enable the Drive API, and then at the bottom click the link to Google Cloud Platform API Dashboard and enable the Drive API there as well.