Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
<!doctype html>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<title>Connect JavaScript - jQuery Login Example</title>
<h1>Connect JavaScript - jQuery Login Example</h1>
<button id="disconnect">Disconnect</button>
<div id="user-info" style="display: none;"></div>
<script src=""></script>
<div id="fb-root"></div>
<script src=""></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) {
// no user, clear display
function clearDisplay() {
Copy link

asbisobirin commented May 31, 2021


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