1
votes

I've just published my addon to G Suite Marketplace for the first time :D

(After about 2 weeks, Google had published our addon today)

And the first thing that I noticed is: A lot of bugs :(

Although I had tested my code with my bound document very carefully.

Those bugs related to this line of code:

Session.getActiveUser().getEmail()

It always returns an empty string, though I had OAuth permission for https://www.googleapis.com/auth/userinfo.email

I guess (but can't be sure) that I need to use this function instead:

Session.getEffectiveUser().getEmail()

I can't be sure because I had updated the code and submitted a new version to G Suite Marketplace but Google didn't publish it yet (maybe because the migration from Addon Store to G Suite Marketplace is still unstable)

So do you have experience with Addon on G Suite Marketplace about this problem?

Should I use getEffectiveUser() instead of getActiveUser() all the time ?


EDIT:

This is the context of the code that runs Session.getActiveUser():

  • After the user has accepted the OAuth permissions
  • The sidebar appeared
  • The client-side code call functionX (that has a call to Session.getActveUser()) using google.script.run.functionX...

According to this guide https://developers.google.com/gsuite/add-ons/concepts/editor-auth-lifecycle#authorization_modes, when using google.script.run, the AuthMode is FULL

1
As the documentation indicates, it's highly context dependent. Can you provide details about the context in which that code is executing? For reference, see the Authorization Modes documentation. If the code is being executed in a context where the authorization mode is anything other than AuthMode.FULL, that explains the empty string being returned.chuckx
@chuckx: Thanks. I edited my question to provide the information about contextHoang Trinh
Questions that look for help debugging code should include a minimal reproducible example (in this case include server side and client side code)Rubén

1 Answers

3
votes

As we can read on the getActiveUser() documentation, you will get a blank string if you can't access the user information. Since the AuthMode can change automatically in some situations (as detailed on the authorization modes documentation), we advise to log it to check if it is on AuthMode.FULL or any other mode. We hope that this is useful for you. Please, don't hesitate to offer us more information for further help.