facebook点击登录

facebook log in on click

本文关键字:登录 facebook      更新时间:2023-09-26

我有以下代码(javascript)

       <script>
            window.fbAsyncInit = function() {
            FB.init({
              appId: '<?=$this->facebook->getAppID()?>', 
              cookie: true, 
              xfbml: true,
              oauth: true
            });
            FB.Event.subscribe('auth.login', function(response) {
                loading();
                alert("test");
                window.location = throute + "login/index/fblogin";                
            });
            FB.Event.subscribe('auth.logout', function(response) {
                window.location.reload();
            });
            FB.Event.subscribe('auth.authResponseChange', function(response) {
                if (response.status=="connected") {
                    alert("test");
                    window.location = throute + "login/index/fblogin";
                }
            });
        };
        (function() {
            var e = document.createElement('script'); e.async = true;
            e.src = document.location.protocol +
              '//connect.facebook.net/en_US/all.js';
            document.getElementById('fb-root').appendChild(e);
        }());       
      </script>

如果用户没有登录fb,一切都很好。

我的问题是,如果用户已经登录fb,他访问网站时会自动登录。我需要他在点击"登录"按钮后登录。

泰寻求帮助。

当用户单击登录按钮时,只需初始化FB应用程序。我猜你是在使用facebooks自己的登录按钮,你不需要这么做。

('#loginButton').click(function(){
     FB.init({
          appId: '<?=$this->facebook->getAppID()?>', 
          cookie: true, 
          xfbml: true,
          oauth: true
        });
    //the rest of the code follows here
});

如果用户已经登录Facebook,他们将在按下你的按钮后直接登录。

如果用户未登录Facebook,则单击您的按钮后会出现登录对话框。