如何使用我的应用脚本获取用户的Gmail? [英] How to get gmail of user use my app script?

查看:55
本文介绍了如何使用我的应用脚本获取用户的Gmail?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当用户在文件gs中使用我的应用程序时,我创建了功能gmail.当我通过文件脚本html调用函数时,它运行但没有gmail?

I create function get gmail when user use my app in file gs. When i call function via file script html it run but don't get gmail ?

我尝试测试打开新的Web浏览器,使用帐户gmail登录并传递应用程序脚本的URL,但不显示我的gmail.

I try test open new web browsers, log in with account gmail and pass URL of apps script but not show my gmail.

.gs文件中的代码:

Code in file .gs:

function checkAccSS(){

 var email = Session.getActiveUser().getEmail();
 Logger.log(email); // I test it show my gmail

 return email;

}

.html文件中的代码:

Code in file .html:


<!DOCTYPE html>
<html>
  <head> 
  </head>
  <body  onload="doLoadGmail()">


    <p id="demo"></p>


    <script>   

         function doLoadGmail(){

           google.script.run.withSuccessHandler(checkGmall).checkAccSS();

         }

         function checkGmall(email){         

          document.getElementById("demo").innerHTML = "Gmail " + email;// not show gmail in html !

          console.log(info); // not show gmail here !

         }

    </script>

  </body>
</html>

推荐答案

据我所知,这是因为执行脚本'checkAccSS'的脚本'doLoadGmail()'仅在加载时调用.您可以添加带有onclick事件的按钮,该按钮可以在不重新加载脚本的情况下执行脚本,但这不会自动完成.

As far as I can see this happens because your script 'doLoadGmail()' that executes the script 'checkAccSS' is only called on load. You could add a button with an onclick event that would execute your script without reloading however this wouldn't do it automaticly.

如果您想自动执行此操作,可以从Ajax查阅文档 https://www.w3schools.com/jquery/jquery_ref_ajax.asp

If you would like to this automaticly you could check the documentation from Ajax https://www.w3schools.com/jquery/jquery_ref_ajax.asp

这篇关于如何使用我的应用脚本获取用户的Gmail?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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