简体   繁体   中英

How to get user email of a Google spreadsheet Add-On?

I created an add-on for Google spreadsheets.

Everytime it runs, it must check the user's email address

Session.getActiveUser().getEmail();

Therefore, I created an onOpen trigger to fetch the email address, but it seems this isn't possible according to Google's documentation here.

Then, how do I use the User Class?

This is how the functon to get the email looks like:

function myFunction() {
  var userEmail=Session.getActiveUser().getEmail();
  Browser.msgBox("Your email address is "+userEmail);
}

I tried so getEffectiveUser() but it gives the developer's email address instead.

I tried sharing the spreadsheet with a second user, he gave permission to show the email bit no matter what I do I always get an empty string!

I need this app to check if the user's email is on a list of another spreadsheet.

Essentially, it's intended that this is nearly impossible, or at least incredibly difficult. As the documentation you linked indicates, you're not able to pull another users email address using a custom function in sheets, and this is a good thing, as it would be easy to farm email addresses using this method on unsuspecting users.

A great rule of thumb is -> If they're not using Google Apps in the same organisation as yourself = You can't get their email address. (A moments thought shows us why this is a good thing. Once you authorise someone to see what your address is, even for a legitimate purpose, you have no idea what they do with it after, and spammers and scammers would love to be able to use Apps script to farm addresses).

The only reasonable solution here is to have the script check for the address, and if a blank string is returned, request the user manually enter their address into a text box into the form/sheet/App etc.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM