views:

159

answers:

1

I'm trying to see if a user is logged into FB on my website. I have the following code below but regardless if I'm logged into my FB account or not the FB.getLoginStatus response is always returning null.

<script type="text/javascript">
window.fbAsyncInit = function() {
FB.init({appId: 'XXXXXXXXXXXXXXX', status: true, cookie: true,
         xfbml: true});
FB.getLoginStatus(function(response) {
  if (response.session) {
    alert('Logged In');
  } else {
    alert('Not Logged In');
  }
});
};

(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>
A: 

So it turns out this was a misinterpretation of the FB docs. The session will only return if the user is connected to the app. To see if the user is logged in but not connected you need to use response.status

Splashlin

related questions