facebook使用自定义侦听器登录

时间:2011-06-09 12:57:12

标签: javascript jquery facebook facebook-graph-api

我正在尝试创建自定义登录注销按钮,我不确定我是否正确实现了facebook JS API:

<html>
<head>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js"></script>
</head>
<body>
<div id="fb-root"></div>
<button id="fb-login">Login</button>
<script>

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


window.fbAsyncInit = function() {
    FB.init({appId: '160525653984605', status: true, cookie: true});
    FB.getLoginStatus(function(response) {
        if (response.session) {
            $("#fb-login").html = "Logout";
            $("#fb-login").unbind();
            $("#fb-login").bind("click", logout);
            console.log('User is logged in.');
        }

          else {
            $("#fb-login").unbind();
            $("#fb-login").bind("click", login);
            console.log('User is not logged in.');
        }
    });
  };

function login(){
        FB.login(function(response) {
            if (response) {
                console.log('Login success. Checking auth_nonce...');
        //      window.location = "http://wall-et.com/index.php/test/welcome/"
                $("#fb-login").html = 'Logout';
            }
            else {
                console.log('Login cancelled.')
            }
        },
        {auth_type: 'reauthenticate', auth_nonce: 'abcd1234' });
}

function logout(){
        FB.logout(function(response) {
            $("#fb-login").html = "Login";
    });
}

</script>
</body>
</html>

2 个答案:

答案 0 :(得分:0)

你有两个功能登录, 更改为退出;)

答案 1 :(得分:0)

您可以使用this link,页面底部包含一个工作示例,您可以使用它。你想要的是什么

相关问题