Home > other >  How to retrieve email address of current user webapp apps script
How to retrieve email address of current user webapp apps script

Time:02-06

i've looked up alot to get session email with this do get and failed to achieve it, and i'm unsure how to get it so i will thanks if some one helped me how to solve this issue to retrieve usermail beside each coordinates excuted.

script proprieties script proprieties

Html Code

<html>
  <head>
    <base target="_top">
  </head>
  <body>

    <button id = "find-me">Show my location</button><br/>
    <p id = "status"></p>
    <a id = "map-link" target="_blank"></a>
   
    <script>
      function geoFindMe() {

        const status = document.querySelector('#status');
        const mapLink = document.querySelector('#map-link');
      
        mapLink.href = '';
        mapLink.textContent = '';
      
        function success(position) {
          
          const latitude  = position.coords.latitude;
          const longitude = position.coords.longitude;
         
          google.script.run.saveCoordinates(latitude,longitude);
                         
          status.textContent = '';
          mapLink.href = 'https://www.openstreetmap.org/#map=18/'   `${latitude}\/${longitude}`;
          mapLink.textContent = `Latitude: ${latitude} °, Longitude: ${longitude} °`;
        }

        function error() {
          status.textContent = 'Unable to retrieve your location';
        }

        if(!navigator.geolocation) {
          status.textContent = 'Geolocation is not supported by your browser';
        } else {
          status.textContent = 'Locating…';
          navigator.geolocation.getCurrentPosition(success, error);
        }

      }

         document.querySelector('#find-me').addEventListener('load', geoFindMe);
            window.onload = geoFindMe
       </script>
      </body>
</html>

here's doget function

function doGet(e) {
  return HtmlService.createHtmlOutputFromFile('index');
}
function saveCoordinates(latitude,longitude){
  const sheet = SpreadsheetApp.getActiveSheet();
  const rowContents = [latitude "," longitude];
  var lastRow = sheet.getLastRow();
var lastColumn = sheet.getLastColumn();
var lastCell = sheet.getRange(lastRow, lastColumn);
  sheet.appendRow(rowContents);
  
}

CodePudding user response:

<!DOCTYPE html>
<html>
<head>
  <base target="_top">
</head>
<body>
  <p id = "1"></p>
  <script src="https://code.jquery.com/jquery-3.2.1.slim.min.js"
    integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous">
  </script>
  <script>
    $(document).ready(function() {
       google.script.run.withSuccessHandler(function (datareturned) {

        alert(datareturned)
        $('#1').text(datareturned)
      }).getuser_email();
  });
  </script>
</body>
</html>

server function

function doGet(e) {
  return  HtmlService.createTemplateFromFile("index").evaluate();
}

function getuser_email(){

   const email = Session.getActiveUser().getEmail();
   return email;

}
  •  Tags:  
  • Related