Facebook JavaScript SDK - getLoginStatus always returns unknown

余生长醉 提交于 2019-12-12 05:01:09

问题


I am creating the application that will aggregate data from different social network profiles. So I have created an interface where client can choose which social network profile will he allow my application to access to. Interface has either a button that user clicks to authorize app or a button that revokes granted privileges to my application if a user changed hers/his mind about giving the right to my application.

My flow is following:

  • On page load I ask Facebook whether the user is logged in
    • If the user is logged in an option to disconnect is provided
    • if the user is not logged in (or the status is unknown <- this is important) the option for logging in is provided.

And this works like it should. But a strange thing happens.

At the beginning

FB.getLoginStatus(loginStatusCallback, true);

function loginStatusCallback(response) {
    if(response.status == 'not_authorized') {
       ....
    } else if(response.status == 'unknown') {
       ....
    } else {
       ....
    }
}

For login I use

FB.login(loginCallback);

Login is successful and I act accordingly. But if I reload page response.status will be 'unknown' even though I am logged in to Facebook and my application is on the list of logged apps on Logged in with Facebook. As far as I understand SDK documentation 'unknown' should be the response if I am not logged in to Facebook (which is equivalent to not being connected in my application). So even if user has already logged in he will be bothered to log in again and that is not acceptable.


回答1:


Looks that the problem was not on my side since it fixed with no code changes. The problem is that I once used FB.logout() and instead of just logging me out of the app Facebook just considered me as logged out.

Logging me back in did not change a thing. I have cleared all cookies from browser and did a re-login and problem ceased to exist.

For disconnecting user from application I do not use FB.logout() instead I revoke privileges with

FB.api("/me/permissions", "delete", logoutCallback);

Now everything works like it should... But to me this looks like an issue with SDK...



来源:https://stackoverflow.com/questions/37702895/facebook-javascript-sdk-getloginstatus-always-returns-unknown

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!