Google Sheet error:"Exception: We're sorry, a server error occurred. Please wait a bit and try again"

1.5k views Asked by At

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?

2

There are 2 answers

0
ale13 On

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.

0
tutuDajuju On

I encountered a similar issue (though with the DriveApp.getFiles() and DriveApp.searchFiles() functions), I was seeing the "Something Went Wrong - Please reload the page to try again" error. After over an hour investigating I've narrowed it down to the Google Cloud Project (GCP) that the problematic AppScript is associated with.

If you've selected a GCP project for the script, then that project must have the appropriate GCP API enabled. For the DriveApp SDK/library I had to enable the Google Drive API (see docs), which then fixed the issue for me.

If the script is still using the default project I found that no additional action was needed; it probably means the underlying GCP project already has all the needed APIs enabled for each supported AppScript integration.

Interestingly, this is mentioned under Advanced services requirements, but it's not clear why DriveApp functions are also affected, as they aren't listed under "advanced services" (we're not using Drive API after all). I created a bug ticket in google's issue tracker to try and get to the bottom of this one.