add-on onInstall - You do not have permission to call getInstallationSource

81 views
Skip to first unread message

Faustino Rodriguez

unread,
Nov 11, 2019, 1:09:17 PM11/11/19
to Google Apps Script Community
In the add-on onInstall() function, the script calls

ScriptApp.getInstallationSource()

And throwing (registered in stack-driver error reporting) a seldom error: 
"You do not have permission to call getInstallationSource"

That function does not list any authorization scopes and supposedly onInstall should have all full access to the script scopes

Any ideas on what is happening there?

Alan Wells

unread,
Nov 11, 2019, 1:32:10 PM11/11/19
to Google Apps Script Community
I don't know, but the G Suite Admin can control whether users can install add-ons from the G Suite Marketplace.


Maybe an admin made a setting restricting users from installing the add-on?

You could try to log the user email to stack driver, and send them an email.

function onInstall() {

try{


  effectiveUsr
= Session.getEffectiveUser().getEmail();//getActiveUser does NOT work in onInstall

 
ScriptApp.getInstallationSource();


}catch(e){
  console
.error("Error: " + e.message + effectiveUsr + "Stack: " + e.stack);//Log error level entry to stack driver
}
}

Faustino Rodriguez

unread,
Nov 12, 2019, 8:06:35 AM11/12/19
to Google Apps Script Community
I am now doing something as you suggested, so far ...
- When catching the getInstallationSource() error, it fails a few lines below with SpreadsheetApp.getActiveSpreadsheet()
- It looks like "a delay" on recognising the scopes authorization
- No idea if the user gets that error message or not

With that logging, I might be able to find if the user actually ends up installing the add-on or not ...

Thanks, Fausto

Alan Wells

unread,
Nov 12, 2019, 9:07:41 AM11/12/19
to Google Apps Script Community
Can you wait to use:

SpreadsheetApp.getActiveSpreadsheet()

until sometime after the installation?
I'd only put code into the onInstall() function that is absolutely necessary.

The nice thing about Stackdriver in the onInstall() function is that you can get error information regardless of the authorization status.

Thanks for letting me know that the suggestion might help.

Faustino Rodriguez wrote:
I am now doing something as you suggested, so far ...
- When catching the getInstallationSource() error, it fails a few lines below with SpreadsheetApp.getActiveSpreadsheet()
- It looks like "a delay" on recognising the scopes authorization
- No idea if the user gets that error message or not

With that logging, I might be able to find if the user actually ends up installing the add-on or not ...

Thanks, Fausto

Faustino Rodriguez

unread,
Nov 13, 2019, 7:57:04 AM11/13/19
to Google Apps Script Community
I have spent sometime already trying to fix a problem I can avoid by following your suggestion "I'd only put code into the onInstall() function that is absolutely necessary"
- What is in your view absolutely necessary to include in onInstall?
- I believe in my case there is nothing like that

Otherwise,
- this is a [recent?] weird seldom error that might be related with the installation process
- even the function ScriptApp.getAuthorizationInfo fails with message "You do not have permission to call getAuthorizationInfo"
- this function by definition should not require authorization, right?
- so I am not sure what is the actual cause and if reducing onInstall calls would fix it

Anyway, I will try to reduce the calls within onInstall and hope that would avoid this problem

Thanks a lot for your suggestions !!

Alan Wells

unread,
Nov 13, 2019, 9:30:21 AM11/13/19
to Google Apps Script Community
onInstall() only runs once.  And there is code that you may only want to run once in the beginning.  But you could have a "Set Up" menu item in the add-on menu if the add-on requires some set-up.  Or whenever the user opens the sidebar, check if the set-up is done.  It's unfortunate that the code would need to test every time whether the set-up was done, but if the onInstall function is failing, that's maybe worse.

There have been some recent errors, but I haven't heard anything about the onInstall function.

ScriptApp.getAuthorizationInfo(ScriptApp.AuthMode.FULL) doesn't have any requirement listed for needing a scope.  So it should run without an error even if the user cancelled the authorization.  But it needs a parameter, and the only valid parameter is: ScriptApp.AuthMode.FULL

In your code, you aren't including the ScriptApp.AuthMode.FULL parameter.

Faustino Rodriguez

unread,
Nov 13, 2019, 9:42:30 AM11/13/19
to Google Apps Script Community
- I just did as you suggested: remove ALL code from onInstall other than calling onOpen, that only create and add the add-on menu
- Check for init-setup on further calls
- Now I am waiting if any errors come this way

- Yes I had the full function call including the parameter, 
ScriptApp.getAuthorizationInfo(ScriptApp.AuthMode.FULL)
- but it was throwing that error anyway

Faustino Rodriguez

unread,
Nov 15, 2019, 11:04:45 AM11/15/19
to Google Apps Script Community
no more onInstall errors for lack of permission in the past 48 hours, after reducing onInstall to an onOpen call
thanks again for your suggestion
Fausto
Reply all
Reply to author
Forward
0 new messages