I have a published button in my web page but i need logout user from facebook after user click in button. How i make it?
I try it:
<html>
<head>
</head>
<body>
<div id="fb-root"></div>
<script>
//initializing API
window.fbAsyncInit = function() {
FB.init({appId: '462904197064938', status: true, cookie: true, xfbml: true});
};
(function() {
var e = document.createElement('script'); e.async = true;
e.src = document.location.protocol +
'//connect.facebook.net/en_US/all.js';
document.getElementById('fb-root').appendChild(e);
}());
</script>
<!-- custom login button -->
<a href="#" onclick="fblogin();return false;">login</a>
<a href="#" onclick="fblogout();return false;">logout</a>
<script>
//your fb login function
function fblogin() {
FB.login(function(response) {
alert("login");
}, {scope:'read_stream,publish_stream,offline_access'});
}
function fblogout() {
FB.login(function(response) {
alert("logout");
});
}
</script>
</body>
</html>
But it not work. The login work fine, but logout not work and not have any error log.
Why it dosent work?
The Facebook SDK has a logout method that you should be able to use. IIRC, you aren’t able to use the GraphAPI to logout.
See https://developers.facebook.com/docs/reference/javascript/FB.logout/.