Goal:
With a Google script add-on, I want to push some contact info from a Google spreadsheet to Google Contacts with minimal user interaction.
Problem:
Whatever I do, I always get an authorization failure.
- When I test the script below in "installed" mode I get an error message: Script execution failure: you don't have the appropriate authorization to do this action. (line 6)
- When I test the script below in "enabled" or in "installed and enabled" mode I get an error message: Script execution failure: you're not authorized to call getContactGroup. (line 11)
(Note: I translated the error messages from french which is my language, so the original english messages may differ slightly. I also renumbered and pretty printed the code)
1 function onInstall(e) {
2 onOpen(e);
3 }
4
5 function onOpen(e) {
6 var spreadsheetName = SpreadsheetApp.getActiveSpreadsheet().getName();
7 createContactsGroupIfNotExists(spreadsheetName);
8 }
9
10 function createContactsGroupIfNotExists(contactsGroupName) {
11 var group = ContactsApp.getContactGroup(contactsGroupName)
12
13 if(! group)
14 contactsGroup = ContactsApp.createContactGroup(contactsGroupName);
15
16 return group;
17 }
I can explain the first error I get as the script can't access yet the spreadsheet it is linked to. But once the script is enabled (or even enabled and installed), shouldn't it would access the user contacts properly.
Google documentation about authorizations say the onOpen() trigger is run in AuthMode.LIMITED which prevent unwanted access to the user data. But I want to run the script as silently as possible (e.g. asking for authorization only once).
Any advice?