Skip to content

Instantly share code, notes, and snippets.

@nazt
Created September 17, 2010 06:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nazt/583825 to your computer and use it in GitHub Desktop.
Save nazt/583825 to your computer and use it in GitHub Desktop.
<!doctype html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<title>Connect JavaScript - jQuery Login Example</title>
</head>
<body>
<h1>Connect JavaScript - jQuery Login Example</h1>
<div>
<button id="disconnect">Disconnect</button>
</div>
<div id="user-info" style="display: none;"></div>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<div id="fb-root"></div>
<script src="http://connect.facebook.net/en_US/all.js"></script>
<script>
// initialize the library with the API key
FB.init({ apiKey: 'ad152b9a2419a3bb5dfdcc58bb7832c9', status:true, logging: true, cookie: true, xfbml: true });
$(document).ready(function() {
FB.getLoginStatus(function(response) {
if (response.session) {
console.log('already logged');
}
else {
FB.login(function(response) {
if(response.session) {
console.log('login completed!')
}
else {
// user is not logged in
}
}, {perms:'read_stream, publish_stream, offline_access, user_photos, friends_photos'});
} // else
}); // getLoginStatus
}); // document.ready
$('#disconnect').bind('click', function() {
FB.api({ method: 'Auth.revokeAuthorization' }, function(response) {
clearDisplay();
});
console.log('disconnected');
});
// no user, clear display
function clearDisplay() {
$('#user-info').hide('fast');
}
</script>
</body>
</html>
@asbisobirin
Copy link

Gimnaa

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment