FB.Event.subscribe(';auth.login';)赢得';不要每次都触发? window.fbAsyninit=函数(){ FB.init({ appId:“我的应用程序ID”, 状态:正确, 曲奇:是的, xfbml:对 }); FB.Event.subscribe('auth.login',函数(响应){ $.ajax({ url:“http://example.com/fbconnect", 成功:函数(){ window.location.reload(); } }); }); }; (职能(d){ var js,id='facebook jssdk';if(d.getElementById(id)){return;} js=d.createElement('script');js.id=id;js.async=true; js.src=“//connect.facebook.net/en_US/all.js”; d、 getElementsByTagName('head')[0].appendChild(js); }(文件); 使用Facebook登录

FB.Event.subscribe(';auth.login';)赢得';不要每次都触发? window.fbAsyninit=函数(){ FB.init({ appId:“我的应用程序ID”, 状态:正确, 曲奇:是的, xfbml:对 }); FB.Event.subscribe('auth.login',函数(响应){ $.ajax({ url:“http://example.com/fbconnect", 成功:函数(){ window.location.reload(); } }); }); }; (职能(d){ var js,id='facebook jssdk';if(d.getElementById(id)){return;} js=d.createElement('script');js.id=id;js.async=true; js.src=“//connect.facebook.net/en_US/all.js”; d、 getElementsByTagName('head')[0].appendChild(js); }(文件); 使用Facebook登录,facebook,connect,Facebook,Connect,它只适用于两种情况。 1-当用户未登录并登录到facebook时,它会触发 2-当用户登录但尚未授权应用程序时,它将触发 第三种不起作用的情况是,当用户登录并且已经授权应用程序时,FB.Event.subscribe('auth.login')不会触发 这里也有同样的问题,我快发疯了。不喜欢Facebook Javascript SDK atm FB.init()中的状态检查非常复杂,当你在页面上添加facebook评论时,它会变得更加困难 我刚刚测试的一个解决方法是使用自己的login按钮并使

它只适用于两种情况。
1-当用户未登录并登录到facebook时,它会触发
2-当用户登录但尚未授权应用程序时,它将触发


第三种不起作用的情况是,当用户登录并且已经授权应用程序时,FB.Event.subscribe('auth.login')不会触发

这里也有同样的问题,我快发疯了。不喜欢Facebook Javascript SDK atm

FB.init()中的状态检查非常复杂,当你在页面上添加facebook评论时,它会变得更加困难

我刚刚测试的一个解决方法是使用自己的login按钮并使用FB.login()方法,在那里可以挂接回调(这将替换auth.login事件的代码)


默认登录事件实际上仅在用户授权应用程序时触发。因此,在注销用户时,您可以撤销授权。但每次登录时,他们都必须使用FB.Event.subscribe('auth.statusChange',handleStatusChange')来“允许”应用程序。

将通知您状态更改


希望对您有所帮助

我遇到了与您相同的问题,并找到了一个函数“getLoginStatus”,您可能会感兴趣

当用户已登录并已授予您的应用程序所有权限时,则无需再次登录,因此不会触发事件

但是,如果“getLoginStatus”的响应为“已连接”,则当用户已登录并已授予应用程序所有权限时,您可以执行希望执行的操作

完整的脚本可能如下所示:

window.fbAsyncInit = function () {
    FB.init({
    ...
    });

    $('#fb-login-button-custom').show().click(function () {
        var scopeList = $(this).data('scope');
        FB.login(function (response) {
            alert('FB.login callback');
            console.log(response);
            document.location.href = document.location.pathname + '?fblogin=1';
        }, { scope: scopeList });
    });
});

window.fbAsyninit=函数(){
FB.init({
appId:'appId',//应用程序ID
channelUrl:'CHANNEL_URL',//频道文件
状态:true,//检查登录状态
cookie:true,//启用cookie以允许服务器访问会话
xfbml:true//解析xfbml
});
FB.getLoginStatus(函数(响应){
如果(response.status===“已连接”){
//用户已登录并连接到您的
//app和response.authResponse提供
//用户ID、有效访问令牌、签名
//请求,以及访问令牌的时间
//和签名的请求都将过期
var uid=response.authResponse.userID;
var accessToken=response.authResponse.accessToken;
FB.api('/me',函数(响应){
if(response.name!=未定义){
log(“欢迎,”+response.name);
}         
});
}else if(response.status===“未授权”){
//用户已登录到Facebook,
//但未连接到应用程序
}否则{
//该用户甚至没有登录到Facebook。
}
});        
//这里有额外的初始化代码
};
//异步加载SDK
(职能(d){
var js,id='facebook jssdk';if(d.getElementById(id)){return;}
js=d.createElement('script');js.id=id;js.async=true;
js.src=“//connect.facebook.net/en_US/all.js”;
d、 getElementsByTagName('head')[0].appendChild(js);
}(文件);
window.fbAsyncInit = function () {
    FB.init({
    ...
    });

    $('#fb-login-button-custom').show().click(function () {
        var scopeList = $(this).data('scope');
        FB.login(function (response) {
            alert('FB.login callback');
            console.log(response);
            document.location.href = document.location.pathname + '?fblogin=1';
        }, { scope: scopeList });
    });
});
<script>
  window.fbAsyncInit = function() {
    FB.init({
      appId      : 'APPID', // App ID
      channelUrl : 'CHANNEL_URL', // Channel File
      status     : true, // check login status
      cookie     : true, // enable cookies to allow the server to access the session
      xfbml      : true  // parse XFBML
    });

    FB.getLoginStatus(function(response) {
      if (response.status === 'connected') {
        // the user is logged in and connected to your
        // app, and response.authResponse supplies
        // the user's ID, a valid access token, a signed
        // request, and the time the access token 
        // and signed request each expire
        var uid = response.authResponse.userID;
        var accessToken = response.authResponse.accessToken;
        FB.api('/me', function(response) {
          if (response.name != undefined ) {
            console.log("Welcome, " + response.name);
          }         
        });
      } else if (response.status === 'not_authorized') {
        // the user is logged in to Facebook, 
        // but not connected to the app
      } else {
        // the user isn't even logged in to Facebook.
      }
    });        

    // Additional initialization code here

  };

  // Load the SDK Asynchronously
  (function(d){
     var js, id = 'facebook-jssdk'; if (d.getElementById(id)) {return;}
     js = d.createElement('script'); js.id = id; js.async = true;
     js.src = "//connect.facebook.net/en_US/all.js";
     d.getElementsByTagName('head')[0].appendChild(js);
   }(document));
</script>