0
votes

I have a Google Script that executes as me. In the script, I want to know the user's email. So I refer to the email of the user accessing my application as Session.getActiveUser().getEmail()

That's not working out at all. Google Script is giving an error, saying Session.getActiveUser().getEmail() is NULL.

When I manually enter a dummy email instead of Session.getActiveUser().getEmail(), the code works perfectly

HEEEEELP

PS: The app MUST execute as me, because it needs to access my contacts.

1

1 Answers

0
votes

You cannot have Session.getActiveUser().getEmail() return the user's email id while the app is running as you. There are some workarounds you can try

  1. Ask for the user's email id explicitly.

  2. Write two scripts - one which is the front end UI etc. that run as the user accessing the app (this allows Session.getActiveUser().getEmail() to return the user's email address). Have a second script that does the tasks where your contacts are accessed. Call the second script from the first by using doPost and doGet methods in your second script. For example,

Script 1:

function whatever(){
  UrlFetchApp.fetch('SERVICE_URL_OF_SCRIPT_2'); 
}

Script 2:

function doGet(e){
  // code to access your contact, get parameters in e.parameters

}