问题
We have a addon published in the new google app scripts add on store, but permissions don't seem to work correctly when using the add on in any spreadsheet other than the initial one it is installed in.
I'm seeing an issue where when a new spreadsheet is created and a user selects 'use this add on' from the 'manage add-ons' menu, our menu items don't get populated. For now we've been telling people to remove the add-on and reinstall to force the permissions flow for full permissions.
I looked at the permissions lifecycle guide at https://developers.google.com/apps-script/add-ons/lifecycle#opening and it appears that our onOpen function should be able to add the menu items in LIMITED permissions mode:
function onOpen(e) {
var menu = SpreadsheetApp.getUi().createAddonMenu();
menu.addItem("About OurApp", 'aboutOurApp');
menu.addItem("Show Sidebar", "showSidebar");
menu.addToUi();
Logger.log(e);
if (e && (e.authMode == ScriptApp.AuthMode.NONE || e.authMode == ScriptApp.AuthMode.LIMITED)) {
return; // once user selects a menu item, full permissions should be asked for according to docs.
} else {
// we have full permissions - show the sidebar.
var ui = HtmlService.createHtmlOutputFromFile('Sidebar')
.setTitle('Our App');
SpreadsheetApp.getUi().showSidebar(ui);
}
}
Anyone know what we are doing wrong?
来源:https://stackoverflow.com/questions/25002352/google-add-on-adding-menu-items-in-limited-mode-app-scripts