Created
September 17, 2010 06:38
-
-
Save nazt/583825 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
<!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> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Gimnaa