如何获取Google电子表格插件的用户电子邮件? [英] How to get user email of a Google spreadsheet Add-On?

查看:88
本文介绍了如何获取Google电子表格插件的用户电子邮件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我为Google电子表格创建了一个附加组件。

每次运行时,都必须检查用户的电子邮件地址。

  Session.getActiveUser()。getEmail(); 

因此,我创建了一个onOpen触发器来获取电子邮件地址,但似乎这是不可能的根据Google的文档



然后,我该如何使用用户类?



这就是获取电子邮件的功能:

  function myFunction(){
var userEmail = Session.getActiveUser()。getEmail();
Browser.msgBox(您的电子邮件地址是+ userEmail);

我试过了 getEffectiveUser()

我试着与第二位用户分享电子表格,他无论做什么都允许显示电子邮件位我总是收到一个空字符串!



我需要这个应用程序来检查用户的电子邮件是否在另一个电子表格列表中。



一个很好的经验法则是 - >如果他们没有在自己的同一组织中使用Google Apps =您无法获取他们的电子邮件地址。 (一段时间的想法告诉我们为什么这是一件好事,一旦你授权某人看到你的地址是什么,即使是为了一个合法的目的,你也不知道他们用它做了什么,垃圾邮件制造者和骗子会喜欢能够使用Apps脚本来处理地址)。



这里唯一合理的解决方案是让脚本检查地址,如果返回空字符串,请求用户手动将他们的地址输入到表单/表格/ App等文本框中。


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.

这篇关于如何获取Google电子表格插件的用户电子邮件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆