Reputation: 65
I followed the instructions on Google: First, when onOpen runs with AuthMode.NONE, I add one item to the menu, telling the user: "Grant permissions". The function called is the function to populate the menu with real entries (which require access to user properties).
When the user clicks it, a small webapp window from Google opens, asking the Google account to connect to and asking if the user allows to give the permissions to the app.
Once this window opens, my script has finished - that's not good. How can I know if the user accepted or declined?
When the user finished, is there a way my script to be called again to populate the menu with real entries?
Currently, even the user granted permissions, the menu is unchanged and I have to select it a second time to create the real menu.
Here my code:
function onOpen(e) {
if (e && e.authMode == ScriptApp.AuthMode.NONE) {
var menu = SpreadsheetApp.getUi().createAddonMenu();
menu.addItem('Grant permissions', 'createMenu');
menu.addToUi();
} else {
createMenu();
}
}
function createMenu() {
var up = PropertiesService.getUserProperties();
// now follows code to fill the menu according to user properties
}
When it hits the PropertiesService.getUserProperties()
, Google authentication is started. But finally it does not run through the onOpen method again to recreate the menu now with real entries (except I close and reopen the spreadsheet)
Meanwhile my AddOn was published. When installing the AddOn, the onInstall(e) function is NOT called - the AddOn menu contains the automtic generated Help entry only. Also logging which I added to the onInstall(e) function is not written to gcp logging.
Upvotes: 1
Views: 243
Reputation: 65
onInstall(e) function is not called - that's a Google problem, see: https://issuetracker.google.com/issues/147016387
Fix was released but not yet in production.
Upvotes: 1