FB.getLoginStatus does not fires callback function

Sándor Tamás picture Sándor Tamás · Sep 23, 2011 · Viewed 18.8k times · Source

I have a difficult problem. Difficult means I searched through the net and StackOverflow as well the whole FBJS SDK documentation and haven't find answer.

I am building a Page Tab application where I'd like to let fans to rsvp events. So I have to check if the user is logged in and if it doesn't I have to login. That sounds pretty easy, but FB.getLoginStatus doesn't fires callback function. This is the code excerpt:

FB.init({
   appId: window.appID,
   status: true,
   xfbml: true,
   cookie: true,
   oauth: true,
   channelUrl: 'http://example.com/fb/channel.html'
 }); 

and then I simply - of course after the user clicks on a button - call FB.getLoginStatus, but it seems it doesn't do anything.

I've already checked sandbox mode, FB.init success, URLs in application settings and developing environment. I can call FB.ui, although FB.ui with method: 'oauth' I get an error message saying " The "redirect_uri" parameter cannot be used in conjunction with the "next" parameter, which is deprecated.". Which is very weird because I didn't used "next" parameter. But when I set next to undefined, it works fine, I get the window, but it says "Given URL is not allowed by the Application configuration.". Expect from that, I can login, then I've got the access_token. But in the new window, getLoginStatus still doesn't do anything.

So any advices are welcome.

Thanks, Tamas

UPDATE:

function onBodyLoad() { //on body onload
    FB.init({
     appId: window.appID,
     status: true,
     xfbml: true,
     cookie: true,
     oauth: true,
     channelUrl: 'http://example.com/fb/channel.html'
    });     
   }
...
function getName() { // on button onclick
 FB.getLoginStatus(function(response){
  if (response.authResponse)
   {
    window.loggedIn = true;
    debugString('Logged in');
   } else
   {
    window.loggedIn=false; 
    debugString('Not logged in');
   }
}, true);
if (window.loggedIn === undefined)   {
     debugString('getLoginStatus did not exec'); // I always get this message
  }

}

UPDATE 2: I created a new App on a different URL, which is configured as a standalone website. There these codes work perfectly, I can getLoginStatus, I can login, etc. Is there any difference working in the context of FB, and in a standalone website, using FB JavaScript SDK?

Answer

Jeff picture Jeff · Sep 29, 2011

FB.getLoginStatus does not fire the callback when you are running the website on a different domain than the one that you registered the app with. I usually find myself in this situation when I am developing locally or on a staging server.

For example, if you registered the site with example.com and your staging server is example.mystagingserver.com, the callback wont fire. In this case, you need to create a second application in Facebook and use the Application ID and Secret for the new app.