FB.事件订阅 - 不会触发任何事件

FB.Event.subscribe - none of the event gets triggered

本文关键字:事件 任何 FB      更新时间:2023-09-26

我正在尝试在我的网页中包含Facebook登录/注册插件。每当我单击登录或单击注销相应的FB时。应该触发事件订阅。但就我而言,登录和注销成功发生。但这些事件都不会被触发。在代码下面找到,

<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);
}());

如果有人能在这里帮助我,那就太好了。提前谢谢。

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

对于 auth.login ,例如,当用户尚未授权您的页面然后授予授权时,就会发生此更改。在第一次中,用户没有您的页面的 facebook cookie 值。当他或她授权您的页面时,cookie值将由FB JSsdk写入,您的脚本将感知auth.login更改事件。下次,当用户再次返回时,cookie 值应该已经存在,并且事件不会触发,因为状态没有更改。

当用户已授权你的应用,但已清理 Cookie 时,也会触发 auth.login 事件。在下一次访问中,FB JS SDK 将不得不再次编写 cookie,事件将发生。

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

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