Logging out of Facebook causing strange behaviour with JS SDK
I am using the Facebo开发者_JS百科ok Javascript SDK to authenticate users on my site. Here is my scenario I am having trouble with.
If I am logged in on my site and on Facebook, then I log off on Facebook it seems that FB.getLoginStatus
is not getting called. Further more if I click on my login button (i.e. call FB.login
) then firebug throws an error "FB.login() called when user is already connected."
On top of all the above if I try to get the facebook user it returns nothing.
So in short, I cannot get the facebook user but I can also not call FB.login
so I am stuck with nothing.
Am I missing something here?
If someone ends their session on facebook.com, their session on your website is still present - though if you tried to get or post data to facebook using that session, it would probably fail. If someone signs out of facebook from facebook.com, you can handle this by subscribing to the auth.sessionChange or auth.logout (https://developers.facebook.com/docs/reference/javascript/FB.Event.subscribe/)
FB.Event.subscribe('auth.sessionChange', function(response) {
alert('The status of the session is: ' + response.status);
});
If you spot that someone has logged out of facebook directly, while using your site, you can log them out from your session with
FB.logout()
After this has happened, your FB.login() won't give that error anymore. The error is saying you are trying to run FB.login() when you already have a session on that page (because remember the session only cleared on facebook.com, not on your site)
精彩评论