FB.getLoginStatus never fires the callback function in Facebook's JavaScript SDK

Dan picture Dan · Apr 21, 2011 · Viewed 10.6k times · Source

The simple thing of calling FB.init (right before </body>) and then FB.getLoginStatus(callback) doesn't fire the callback function.

After some debugging, I think the SDK is stuck in the "loading" (i.e. FB.Auth._loadState == 'loading') phase and never gets to "loaded", so all callbacks are queued until the SDK has loaded. If I force-fire the "loaded" event during debugging - with FB.Event.fire('FB.loginStatus', 'loaded') in case you're intersted - then the callbacks are invoked correctly.

Extra details that might be relevant:

  1. My app is a facebook iframe app (loaded via apps.facebook.com/myapp)
  2. I'm using IE9. The same behavior happens in Chrome
  3. The app is hosted in http://localhost

What's going on? Why is the SDK never gets to loaded?

Thanks

UPDATE: Just tried it on Chrome and it worked (not sure why it didn't work before). Still doesn't work in IE

Answer

phreakhead picture phreakhead · May 10, 2011

I had this same problem in Firefox 3.5 on Windows, but only on the very first log in to the page (probably because it was a slower machine and there was some weird timing issues going on).

I fixed it by forcing FB to refresh the login status cookie every time it checks:

FB.getLoginStatus(callback, true); //second argument forces a refresh from Facebook's server. 

Without "force=true", sometimes it wouldn't fire the callback.