Created
April 13, 2013 16:34
-
-
Save azenla/5379106 to your computer and use it in GitHub Desktop.
Google+ Login
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
<!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