2012-08-12 90 views
0

我正在尝试在我的网页中包含Facebook登录/注册插件。每当我点击登录或点击注销时,都应该触发相应的FB.Event.subscribe。但在我的情况下,登录和注销成功。但这些事件都没有被触发。 找到下面的代码,FB.Event.subscribe - 没有事件被触发

<div id="fb-root"></div> 
window.fbAsyncInit = function(){ 
    FB.init({ 
     appId : 'xxxxxxxxxxxxxxxxxxxx', 
     status : true, 
     cookie : true, 
     oauth : true, 
     xfbml : true 
    }); 

    FB.Event.subscribe('auth.login', function(response) { 
     FB.api('/me', function(response) { 
     alert('You have successfully logged in, '+response.name+"!"); 
     }); 
    });  

    FB.Event.subscribe('auth.logout', function(response) { 
     FB.api('/me', function(response) { 
      alert('You have successfully logged out, '+response.name+"!"); 
     }); 
    }); 

    FB.getLoginStatus(function(response) { 
     if (response.session) { 
      alert('Hello'); 
     } 
    }); 
}; 

(function() { 
    var e = document.createElement('script'); 
    e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js'; 
    document.getElementById('fb-root').appendChild(e); 
}()); 

这将是巨大的,如果有人可以帮助我在这里。提前致谢。

回答

0

这些事件仅在用户状态CHANGES时触发。

例如,对于auth.login,如果用户尚未授权您的页面并授予授权,则会发生此更改。在这第一次,用户没有您的页面的Facebook Cookie值。当他或她授权您的页面时,Cookie值将由FB JS SDK编写,您的脚本将会感知auth.login更改事件。下一次,当用户再次返回时,Cookie值应该已经存在,并且事件不会触发,因为状态没有变化。

当用户已经授权您的应用程序但清理了Cookie时,auth.login事件触发。在下次访问中,FB JS SDK将不得不再次写入cookie,并且事件将发生。

我不确定关于auth.logout事件,因为我没有使用它,但据我所知,它与您的应用程序没有关系,但与用户的Facebook帐户的会话状态有关。

我建议您在脚本执行过程中监视页面上的cookie值更改,以便更好地了解事件发生的时间。