hhsb
hhsb

Reputation: 582

Unable to get Active user's email

I tried to log the user's email for debugging purposes. I used Session.getActiveUser().getEmail(). I received the following error.

Exception: You do not have permission to call Session.getActiveUser.getEmail() Required permissions: https://www.googleapis.com/auth/userinfo.email

Hence i added the https://www.googleapis.com/auth/userinfo.email scope to my addon. Now I get the following error

The script does not have permission to get the active user's identity.

However, I don't see the error if I run it on my account(Gsuite) or any other users in our domain. FYI: I am the owner of the addon.

Am I missing any scopes ?

Upvotes: 5

Views: 5829

Answers (3)

Karishma Gulati
Karishma Gulati

Reputation: 763

Neither getActiveUser() nor getEffectiveUser() were working for me. There's an issue open with Google right now and some suggestions in this thread helped me:

(1) Try copying the scopes from (File->Project Properties->Scopes) into the manifest file (View->Show Manifest File) following the instructions give here.

(2) The issue is with the new App Script runtime powered by Chrome v8. If (1) doesn't work (it didn't work for me) --> disable the App Script runtime as follows: (Run -> Disable App Script runtime powered by Chrome V8). The project will now run with Apps Script Legacy which does not have this issue.

Note: (2) is applicable until the issue is resolved.

Upvotes: 1

hhsb
hhsb

Reputation: 582

Replacing getActiveUser() by getEffectiveUser() seem to make it work.

Upvotes: 4

I think the best explanation is in the official docs. Addon users context does not assume obligatory authorization and getEmail method may return a blank string.

Upvotes: 3

Related Questions