问题
If I am logged into facebook.com, I expect a call to FB.getLoginStatus will return a status='not_authorized'. Instead it returns status='unknown', even if I pass true for the 'force' parameter.
If I call FB.login, and then call FB.getLoginStatus, I get status='connected'. Makes sense.
If I call FB.login, reload the page, and then call FB.getLoginStatus, I get status='unknown'. Does not make sense. If I add 'true' as the second parameter (i.e. force), I still get status='unknown'. (I expect status='not_authorized' in this case.)
There doesn't seem to be a way to get status='not_authorized' in practice.
Am I doing something wrong? Is this a bug in FB.getLoginStatus or its documentation?
Here is a minimal test page: http://pastebin.com/NqiBXni2
Context:
I am writing a website widget that displays posts for a public Facebook page. (This can be accessed without prompting the user via an app access token.) Each post has a "Like" / "Unlike" link. In order to determine whether to display "Like" or "Unlike", I need to know what the browsing user's Facebook ID is so that I can check whether it is in the post's list of likes.
回答1:
Maybe you have third party cookies disabled.
回答2:
And to elaborate slightly on David's answer, Facebook describes this as a "by design" result when 3rd party cookies are disabled.
Unfortunately, I'm not sure of the most graceful way of handling this -- at least in my site, I need an oath token to load some data.
回答3:
I had similar issue, even when the 3rd party cookie is not disabled. What I did to bypass is: if I get 'unknown' response, I will call FB.login and inside that call the FB.loginStatus again. This time, FB returned correct value.
来源:https://stackoverflow.com/questions/9337619/fb-getloginstatus-always-returns-status-unknown