How to get gmail of user use my app script?

余生长醉 提交于 2019-12-25 01:16:37

问题


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 ?

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

Code in file .gs:

function checkAccSS(){

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

 return email;

}

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>


回答1:


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.

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



来源:https://stackoverflow.com/questions/56785787/how-to-get-gmail-of-user-use-my-app-script

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!