Created
December 8, 2010 06:26
-
-
Save levity/732974 to your computer and use it in GitHub Desktop.
Facebook Connect
This file contains hidden or 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
<html> | |
<body> | |
<div id="login" style="display: none"> | |
<fb:login-button perms="email"></fb:login-button> | |
</div> | |
<div id="logout" style="display: none"> | |
<button onclick="FB.logout()">Log out</button> | |
</div> | |
<div id="fb-root"></div> | |
<script> | |
window.fbAsyncInit = function() { | |
FB.init({appId: 'your app id here', status: true, cookie: true, xfbml: true}); | |
FB.Event.subscribe('auth.sessionChange', function(response) { | |
if (response.session) { | |
// A user has logged in, and a new cookie has been saved | |
alert('logged in'); | |
} else { | |
// The user has logged out, and the cookie has been cleared | |
alert('logged out'); | |
} | |
window.location.reload(); | |
}); | |
FB.getLoginStatus(function(response) { | |
if (response.session) { | |
// logged in and connected user, someone you know | |
document.getElementById("logout").style.display = 'block'; | |
} else { | |
// no user session available, someone you dont know | |
document.getElementById("login").style.display = 'block'; | |
} | |
}); | |
}; | |
(function() { | |
var e = document.createElement('script'); e.async = true; | |
e.src = document.location.protocol + | |
'//connect.facebook.net/en_US/all.js'; | |
document.getElementById('fb-root').appendChild(e); | |
}()); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment