When I click on logout... I get this exception in console:
FB.logout() called without an access token.
Question: I already have Access token saved in Session and I have access to it in Client side also. I already checked this answer and could not understand that how can I invoke handleSessionResponse
method and how what will be the response value when I click on logout button? https://stackoverflow.com/a/8430670/726802
I have below code in layout page(master page).
<script>
window.fbAsyncInit = function() {
FB.init({
appId : '{!! env("FACEBOOK_APP_ID") !!}',
xfbml : true,
version : '{!! env("Facebook_Version") !!}'
});
FB.AppEvents.logPageView();
};
(function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) {return;}
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/en_US/sdk.js";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
</script>
Below is the code in blade(content page)
<ul class="nav nav-sidebar">
<li class="active"><a href="#" onclick="logout();">Logout</a></li>
</ul>
<script>
function checkLoginState() {
FB.getLoginStatus(function(response) {
if (response.status === 'connected') {
} else {
}
});
}
function logout() {
debugger;
FB.logout(function(response) {
debugger;
// user is now logged out
});
}
</script>
It seems that the access token is not persistent when change of page, try store the session in a cookie as said CBroe in a comment, something like this:
<script>
window.fbAsyncInit = function() {
FB.init({
appId : '{!! env("FACEBOOK_APP_ID") !!}',
xfbml : true,
status : true,
cookie : true,
version : '{!! env("Facebook_Version") !!}'
});
FB.AppEvents.logPageView();
};
(function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) {return;}
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/en_US/sdk.js";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
</script>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With