r/GoogleAppsScript • u/elazard • Nov 14 '20
Question get user email in a web app run as me
Hi everyone,
for a bit of background, I work for a big company that wont allow me to make the tools to make my job faster so I am using a grey zone to be able to work on the company's data : using a google sheet as back end for a web app . it works fine for the most part. (as a side note: I am not a developer, I am an enthusiast so the questions are probably stupid, please bear with me :))
ok so my question : I would like to be able to retrieve the user's email when they visit my web app. I would use it as a way to pre fill certain fields and personalise the experience a bit. however considering I am using a google sheet as back end, I need to execute the app "as me" as far as I understand, if not I will need to give everyone access to the sheet and that's not desirable (I want users to add data in a controlled manner) nor practical. is that correct?
Is it also correct that I cannot retrieve the actual user's email if the web app runs 'as me'? if both are correct how do you guys do it? is there a way to get the user's email if the script is run as me? or is there a way to not need to give access to the backend spreadsheet to everyone in my company if I run the web app as the user?
thank you in advance !
2
u/takishan Nov 15 '20
You can do this by having them logged in as their account so you can use the easy GAS function to get their email info, and then using the Sheets API to modify the sheet. Not the GAS sheets stuff, but the API you can run outside of GAS. Let me find link...
Here: https://developers.google.com/sheets/api
Be warned, it's kinda shitty working with the sheets api after getting used to how convenient GAS is lol
2
5
u/shm613 Nov 14 '20
That is correct you will need to set the script to run as you in order to not have to share the sheet with everyone but you can get the email for the person loading the app with the following function.
Session.getActiveUser();
I have had to do the same thing with my company because IT restricts access to most things within Gsuite.