FB.getLoginStatus never fires the callback functio

2019-02-12 14:15发布

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

6条回答
Viruses.
2楼-- · 2019-02-12 14:56

I understand that this question is a little old now, but I ran across it searching for solutions.

Double-check what you have set in your Facebook app configuration under the section "Website with Facebook Login". The Site URL domain must match the domain your page with the FB.getLoginStatus (and other related auth Javascript) is served from.

After hours of struggling, I realized that I could not reuse an existing app configuration I had on a new server and had to create a new app to handle the website login for this new server.

The other answers are probably equally valid in your specific case, but since there may be others like me who have struggled for a while on this, hopefully this gives you one other place to check. Making a new app with the correct Site URL was the answer in my particular case.

查看更多
爷、活的狠高调
3楼-- · 2019-02-12 14:57

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.

查看更多
相关推荐>>
4楼-- · 2019-02-12 14:58

I also ran into this issue specifically in Chrome. I tried calling it on page load and after a user-initiated action with no success.

It turned out that it was not a cross-domain issue. The getLoginStatus() call was being blocked by the Un-Passwordise extension in Chrome. As soon as I disabled the extension, it worked perfectly, even on page load.

More info about this issue here: Chrome-only cross-domain scripting errs in Facebook iFrame App upon FB.Login(..)

查看更多
萌系小妹纸
5楼-- · 2019-02-12 14:58

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.

查看更多
放我归山
6楼-- · 2019-02-12 15:14

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.

查看更多
We Are One
7楼-- · 2019-02-12 15:18

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 :)

查看更多
登录 后发表回答