Recently, I encountered a puzzling issue with my script that utilizes the Google Picker API. During testing, everything worked flawlessly until I decided to publish it as a private add-on. From that point on, the script's getOAuthToken function started throwing an error message that lacked any helpful information:
Exception: We're sorry, a server error occurred. Please wait a bit and try again. at getOAuthToken(Code:37:12)
Here are the troubleshooting steps I have taken so far:
- Created a new API key
- Added the script owner to the GCP project (using a generic Google account)
- Enabled the Picker API in the add-on's GCP project and generated a new key
The API key has the following configurations:
- Application restrictions: HTTP referrers
- Website restrictions:
- *.google.com
- *.googleusercontent.com
- API restrictions: Don't restrict key
These settings had been functional prior to publication.
Also, included below is the code snippet for the Google Picker based on the boilerplate provided in the Google API documentation:
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="https://ssl.gstatic.com/docs/script/css/add-ons.css">
<script>
// Script code here
</script>
</head>
<body>
<div>
<p id='result'></p>
</div>
<script src="https://apis.google.com/js/api.js?onload=onApiLoad"></script>
<script>
window.onload = getOAuthToken;
</script>
</body>
</html>
Please note that the server-side implementation of getOAuthToken is also available for reference.
// Server-side function code here
After further investigation, I am now encountering these errors consistently whenever attempting to access the Drive app within the script. The same error is triggered when I use functions like DriveApp.getFolderById(id)
or DriveApp.getFileById(id)
. Despite including scopes in my manifest file, the issue persists. Here is a snippet of my manifest:
{
"timeZone": "Europe/Paris",
"dependencies": {
},
"exceptionLogging": "STACKDRIVER",
"runtimeVersion": "V8",
"oauthScopes": [
"https://www.googleapis.com/auth/drive",
"https://www.googleapis.com/auth/spreadsheets",
"https://www.googleapis.com/auth/script.container.ui",
"https://www.googleapis.com/auth/userinfo.email",
"https://www.googleapis.com/auth/spreadsheets"
]
}