Facebook JavaScript SDK-getLoginStatus始终返回未知 [英] Facebook JavaScript SDK - getLoginStatus always returns unknown

查看:84
本文介绍了Facebook JavaScript SDK-getLoginStatus始终返回未知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建应用程序,该应用程序将汇总来自不同社交网络配置文件的数据.因此,我创建了一个界面,客户可以在该界面中选择允许我的应用程序访问的社交网络配置文件.界面具有用户单击以授权应用程序的按钮,或者如果用户改变了对授予我的应用程序权限的想法,则该按钮可以撤消授予我的应用程序授予的特权.

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.

我的流程如下:

  • 在页面加载时,我问Facebook用户是否已登录
    • 如果用户已登录,则提供了断开连接的选项
    • 如果用户未登录(或状态未知-<-这很重要),则提供用于登录的选项.
    • 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.

      开头

      FB.getLoginStatus(loginStatusCallback, true);
      
      function loginStatusCallback(response) {
          if(response.status == 'not_authorized') {
             ....
          } else if(response.status == 'unknown') {
             ....
          } else {
             ....
          }
      }
      

      我使用登录名

      FB.login(loginCallback);
      

      登录成功,我将采取相应行动.但是,如果我重新加载页面response.status将是'unknown',即使我登录到Facebook并且我的应用程序位于通过Facebook登录"上的已登录应用程序列表中.据我了解,如果我未登录Facebook(相当于未连接到我的应用程序),则应该以SDK文档'未知'作为响应.因此,即使用户已经登录,他也将再次登录,这是不可接受的.

      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.

      推荐答案

      该问题不在我这边,因为它无需更改代码即可解决.问题在于,我曾经使用FB.logout(),而不仅仅是将我从应用程序中注销,Facebook只是认为我已注销.

      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.

      重新登录我并没有改变任何事情.我已经从浏览器中清除了所有cookie,并重新登录,问题不再存在.

      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.

      要断开用户与应用程序的连接,我不使用FB.logout(),而是使用

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

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

      现在一切正常,应该...但是对我来说,这似乎是SDK的问题...

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

      这篇关于Facebook JavaScript SDK-getLoginStatus始终返回未知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆