Skip to content

Instantly share code, notes, and snippets.

@azenla
Created April 13, 2013 16:34
Show Gist options
  • Save azenla/5379106 to your computer and use it in GitHub Desktop.
Save azenla/5379106 to your computer and use it in GitHub Desktop.
Google+ Login
<!DOCTYPE html>
<html>
<head>
<title>Google+ Login</title>
<script type="text/javascript">
(function() {
var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true;
po.src = 'https://apis.google.com/js/client:plusone.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);
})();
function signinCallback(authResult) {
if (authResult['access_token']) {
document.getElementById('signinButton').setAttribute('style', 'display: none');
var accessToken = authResult['access_token'];
} else if (authResult['error']) {
console.log('There was an error: ' + authResult['error']);
return;
}
var data = httpGet("https://www.googleapis.com/plus/v1/people/me?access_token=" + accessToken);
var json = JSON.parse(data);
document.write(json.displayName);
function httpGet(theUrl)
{
var xmlHttp = null;
xmlHttp = new XMLHttpRequest();
xmlHttp.open( "GET", theUrl, false );
xmlHttp.send( null );
return xmlHttp.responseText;
}
}
</script>
</head>
<body>
<span id="signinButton">
<span
class="g-signin"
data-callback="signinCallback"
data-clientid="756381599905.apps.googleusercontent.com"
data-cookiepolicy="single_host_origin"
data-requestvisibleactions="http://schemas.google.com/AddActivity"
data-scope="https://www.googleapis.com/auth/plus.login">
</span>
</span>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment