mehrshaddarzi
7/9/2018 - 9:08 AM

login with Gmail in javascript

login with Gmail in javascript

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <meta name="google-signin-client_id" content="/*Client Id*/">
</head>
<body>
    
    <div id="my-signin2"></div>


    <script src="https://apis.google.com/js/platform.js?onload=renderButton" async defer></script>
  <script>
    function onSuccess(googleUser) {
      var profile = googleUser.getBasicProfile();
      console.log('ID: ' + profile.getId()); // Do not send to your backend! Use an ID token instead.
      console.log('Name: ' + profile.getName());
      console.log('Image URL: ' + profile.getImageUrl());
      console.log('Email: ' + profile.getEmail()); // This is null if the 'email' scope is not present.
    }
    function onFailure(error) {
      console.log(error);
    }
    function renderButton() {
      gapi.signin2.render('my-signin2', {
        'scope': 'profile email',
        'width': 240,
        'height': 50,
        'longtitle': true,
        'theme': 'Light',
        'onsuccess': onSuccess,
        'onfailure': onFailure
      });
    }

    </script>
</body>
</html>