Last active
March 11, 2024 17:00
-
-
Save heldrida/6232556 to your computer and use it in GitHub Desktop.
Facebook Javascript SDK: Basic Login and Logout example
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
<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
I'm new in programming and I'm trying to add a facebook login into a a form, but I don't after many attempts why it doesn't work. Here is the codes, please I seriously need your help