谷歌脚本:不能引用使用Session.getActiveUser用户() [英] Google script: cannot refer to users using Session.getActiveUser()

查看:455
本文介绍了谷歌脚本:不能引用使用Session.getActiveUser用户()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个谷歌的脚本执行的我。
在脚本中,我想知道用户的电子邮件。
所以,我指的是用户访问我的应用程序作为Session.getActiveUser的电子邮件()。getEmail()

I have a Google Script that executes as me. In the script, I want to know the user's email. So I refer to the email of the user accessing my application as Session.getActiveUser().getEmail()

这是不工作了的。谷歌脚本是给一个错误,说Session.getActiveUser()。getEmail()为NULL。

That's not working out at all. Google Script is giving an error, saying Session.getActiveUser().getEmail() is NULL.

当我手动输入一个虚拟的电子邮件,而不是Session.getActiveUser()。getEmail()时,code完美的作品

When I manually enter a dummy email instead of Session.getActiveUser().getEmail(), the code works perfectly

HEEEEELP

PS:应用程序必须执行的我,因为它需要访问我的联系人

PS: The app MUST execute as me, because it needs to access my contacts.

推荐答案

您不能 Session.getActiveUser()。getEmail()返回用户的电子邮件ID,而应用程序运行你。有一些解决方法可以尝试

You cannot have Session.getActiveUser().getEmail() return the user's email id while the app is running as you. There are some workarounds you can try


  1. 询问用户的电子邮件标识明确。

  1. Ask for the user's email id explicitly.

写两个脚本 - 其中一个是前端的用户界面等,由于用户访问应用程序运行(这允许Session.getActiveUser()getEmail()返回用户的电子邮件地址)。有,做您的联系人访问的任务,第二个脚本。
通过使用你的第二个脚本的doPost和方法的doGet调用从第一个第二个脚本。
例如,

Write two scripts - one which is the front end UI etc. that run as the user accessing the app (this allows Session.getActiveUser().getEmail() to return the user's email address). Have a second script that does the tasks where your contacts are accessed. Call the second script from the first by using doPost and doGet methods in your second script. For example,

脚本1:

function whatever(){
  UrlFetchApp.fetch('SERVICE_URL_OF_SCRIPT_2'); 
}

脚本2:

function doGet(e){
  // code to access your contact, get parameters in e.parameters

}

这篇关于谷歌脚本:不能引用使用Session.getActiveUser用户()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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