Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 524
Dan Avatar asked Apr 21 '11 08:04

Dan


People also ask

How to enable JavaScript SDK for Facebook Login?

Enable JavaScript SDK for Facebook LoginSelect Settings in the left side navigation panel and under Client OAuth Settings, enter your redirect URL in the Valid OAuth Redirect URIs field for successful authorization.

What is Facebook SDK for JavaScript?

The Facebook SDK for JavaScript provides a rich set of client-side functionality that: Enables you to use the Like Button and other Social Plugins on your site. Enables you to use Facebook Login to lower the barrier for people to sign up on your site. Makes it easy to call into Facebook's Graph API.

Is JavaScript used in Facebook?

Facebook only uses one language in the Front-end that is JavaScript. JavaScript is the most popular programming language today as it is used by almost every platform in the front-end development that you visit today.

How to implement Facebook OAuth?

Click on Settings in the sidebar under Facebook Login. Turn on Client OAuth Login. Turn on Web OAuth Login. Put the valid redirect URL on "Valid OAuth redirect URIs".


4 Answers

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.

like image 182
phreakhead Avatar answered Nov 02 '22 18:11

phreakhead


I had the exact same problem, and I solved it disabling "Secure Browsing" in the Facebook Security settings. Keeping Secure Browsing on forces the pages as "https", but I had no "Secure Canvas URL" set up, and this gave me a lot of errors in the console as well.

Hope this may help someone :)

like image 27
tyrion Avatar answered Nov 02 '22 16:11

tyrion


In my experience, getLoginStatus() never calls the callback in Firefox when third-party cookies are disabled.

The original poster mentioned his application is hosted on http://localhost. I've never had luck with that, and believe it will cause problems.

Just today, I've had problems where getLoginStatus is not calling the callback on any browser, unless the user is actually connected to the app! I'm hoping this is a bug on facebook's end that they will solve.

like image 26
Dave Cohen Avatar answered Nov 02 '22 17:11

Dave Cohen


Yet another possibility for FB.getLoginStatus not firing its callback is when using a "test" user account that has not been authorized to view that application. Its pretty bad that facebook doesn't give you any error messages. I have also seen failed callbacks on bad appIds and redirectUrls.

like image 1
trcarden Avatar answered Nov 02 '22 16:11

trcarden