Last active
June 23, 2019 06:41
-
-
Save jazeabby/813b459b09ed44a8c41ffc40fdbf14ab to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#header file | |
<meta name="google-signin-client_id" content="{{your-google-client-id}}"> | |
#google js package to include | |
<script src="https://apis.google.com/js/platform.js?onload=renderButton" async defer></script> | |
#html button div | |
<div id="my-signin2"></div> | |
#javascript code | |
<script> | |
function renderButton() { | |
gapi.signin2.render('my-signin2', { | |
'scope': 'profile email', | |
'height': 50, | |
'longtitle': true, | |
'theme': 'dark', | |
'onsuccess': onSuccess, | |
'onfailure': onFailure | |
}); | |
} | |
function onSuccess(googleUser) { | |
// we have googleUser as an object to get user details | |
onSignIn(googleUser); | |
// console.log('Logged in as: ' + googleUser.getBasicProfile().getName()); | |
} | |
function onFailure(error) { | |
console.log(error); | |
} | |
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. | |
} | |
</script> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment