0xh8h
0xh8h

Reputation: 3509

getActiveUser() doesn't return the user?

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():

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

Upvotes: 1

Views: 2600

Answers (1)

Jacques-Guzel Heron
Jacques-Guzel Heron

Reputation: 2598

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.

Upvotes: 3

Related Questions