-
-
Save khle/3d9470dd9011d83b27e763e345d039c7 to your computer and use it in GitHub Desktop.
Facebook Javascript SDK: Basic Login and Logout example
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
<div id="fb-root"></div> | |
<script> | |
window.fbAsyncInit = function() { | |
FB.init({ | |
appId: 'xxxxxxxxxxxxx', | |
status: true, | |
cookie: true, | |
xfbml: true | |
}); | |
}; | |
// Load the SDK asynchronously | |
(function(d){ | |
var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0]; | |
if (d.getElementById(id)) {return;} | |
js = d.createElement('script'); js.id = id; js.async = true; | |
js.src = "//connect.facebook.net/en_US/all.js"; | |
ref.parentNode.insertBefore(js, ref); | |
}(document)); | |
function login() { | |
FB.login(function(response) { | |
// handle the response | |
console.log("Response goes here!"); | |
}, {scope: 'read_stream,publish_stream,publish_actions,read_friendlists'}); | |
} | |
function logout() { | |
FB.logout(function(response) { | |
// user is now logged out | |
}); | |
} | |
var status = FB.getLoginStatus(); | |
console.log(status); | |
</script> | |
<button onclick="javascript:login();">Login Facebook</button> | |
<br> | |
<button onclick="javascript:logout();">Logout from Facebook</button> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment