9

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?

Lee S
  • 91
  • 1
  • 1
  • 2
  • Does this answer your question? [how to indentify user using google apps script?](https://stackoverflow.com/questions/12172849/how-to-indentify-user-using-google-apps-script) – Rubén May 27 '20 at 18:03

1 Answers1

17

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);
 
OblongMedulla
  • 1,471
  • 9
  • 21
  • 4
    That is what I'm using to get the e-mail, but it only gets the e-mail of the user running the script. So I have to then have the script run as the user. I'd prefer to run the script as myself or a service account, because when run as the user, then I need to have the docs/sheets the script accesses set to be shared with that user. If I ran it as myself, and was able to get the users e-mail address somehow, I could avoid having to set those permissions. – Lee S May 11 '17 at 15:32