1

I want to create a login system that can also use FB's login. So I've setup the FB object and SDK in my page and then subscribed to the auth.authResponseChange event and added an anonymous function to do stuff if I'm logged, not logged or not authorized.

When I'm logged it works properly. When I'm not logged or not authorized, it does nothing. I think it just doesn't enter into the anonymous function either, because I've put a console.log() before the if and it does nothing.

Here's my code:

// Facebook stuff
window.fbAsyncInit = function()
{
  FB.init({
    appId      : 'my id blabla', // App ID
    channelUrl : 'my channel.html bla bla', // Channel File
    status     : true, // check login status
    cookie     : true, // enable cookies to allow the server to access the session
    xfbml      : true  // parse XFBML
  });

  FB.Event.subscribe('auth.authResponseChange', function(response)
  {
    console.log("Running function");

    if(response.status === "connected")
    {
        console.log("Connected and authorized");
    }
    else if (response.status === 'not_authorized')
    {
        console.log("Not authorized");
    }
    else
    {
        console.log("Not connected");
    }
  });
};

// Load the SDK asynchronously
(function(d)
{
   var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];
   if (d.getElementById(id)) {return;}
   js = d.createElement('script'); js.id = id; js.async = true;
   js.src = "//connect.facebook.net/en_US/all.js";
   ref.parentNode.insertBefore(js, ref);
}(document));
4

1 回答 1

0

我有同样的问题,但是如果你订阅事件'auth.statusChange'而不是'authResponseChange',你可以知道他是否'连接'到facebook并授权你的应用程序或者他是否连接到fb但没有授权。

此外,如果您使用 Facebook 建议不要使用的 FB.getLoginStatus,您可以知道用户处于三种状态(已连接、未授权或未连接)中的哪一种。

于 2013-09-12T00:25:36.733 回答