Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Apps Script - Get users email address

I've got a Google apps script project running on a Google site. The site requires users to sign in, and it only open to users on this G-suite domain.

The scripts I have are for allowing users to do voting, get into a queue of speakers, and some other tasks.

Currently all the functions in the background would work fine running as "Me" which I prefer, however I need to know the e-mail address of the user running the script (viewing the Google site). Is there any way for me to get the e-mail address of the signed in user viewing the page that is running the script, while running the actual script as me?

If not, can I have one script run as the user, then call another script that runs as me?

like image 603
Lee S Avatar asked May 08 '17 13:05

Lee S


1 Answers

have you tried logging these? https://developers.google.com/apps-script/reference/base/session#getActiveUser()

 // Log the email address of the user under whose authority the script is running.
 var email = Session.getEffectiveUser().getEmail();
 Logger.log(email);

 // Log the email address of the person running the script.
 var email = Session.getActiveUser().getEmail();
 Logger.log(email);
 
like image 56
OblongMedulla Avatar answered Oct 09 '22 03:10

OblongMedulla