Stats

Thursday 8 March 2018

Adding Google Sign In to Your Web Application Code

<script src="https://apis.google.com/js/platform.js" async defer></script>

<meta name="google-signin-client_id" content="YOUR_CLIENT_ID.apps.googleusercontent.com">

<div class="g-signin2" data-onsuccess="onSignIn"></div>

function onSignIn(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.
}