FB.logout功能不起作用

时间:2016-02-29 20:25:06

标签: facebook facebook-graph-api

如果我通过我的网站登录并注销,它运行正常。

如果我只是通过Facebook网站登录然后访问我的网站,他会认出我已登录并显示我的姓名和facebook piture,但我无法通过我的网站注销facebook ,它总是显示我已登录,即使我关闭了facebook页面。

这是我的代码:

<script>
    window.fbAsyncInit = function() {
        FB.init({
            appId      : '123456789123456789', //fake number
            status     : true, // check login status
            cookie     : true, // enable cookies to allow the server to access the session
            xfbml      : true,  // parse XFBML
            version    : 'v2.5'
        });

        FB.getLoginStatus(function(response) {
            if (response.status === 'connected') {
                $('#loginButton').css('display', 'none');
                $('#headerUserMenu').addClass('logged-in');
                var uid = response.authResponse.userID;
                var accessToken = response.authResponse.accessToken;
                getUserInfo();
                getPhoto();
            } else if (response.status === 'not_authorized') {
                console.log('LOGADO MAS NÃO AUTORIZADO');
            } else {
                console.log('DESLOGADO!');
                $('#loginButton').css('display', 'inline-block');
            }
        },{scope: 'public_profile, email'});
    };

    (function(d, s, id){
     var js, fjs = d.getElementsByTagName(s)[0];
     if (d.getElementById(id)) {return;}
     js = d.createElement(s); js.id = id;
     js.src = "//connect.facebook.net/pt_BR/sdk.js";
     fjs.parentNode.insertBefore(js, fjs);
     }(document, 'script', 'facebook-jssdk'));

    function Login() {
        FB.login(function(response) {
            if (response.authResponse) {
                console.log('Bem Vindo! Processando suas informações... ');
                FB.api('/me?fields=name,email,first_name,last_name', function(response) {
                    $('#userProfileName').html(response.name);
                });
                getPhoto();
                $('#loginButton').css('display', 'none');
                $('#headerUserMenu').addClass('logged-in');
            } else {
                console.log('Usuário cancelou o login ou não está autorizado');
            }
        },{scope: 'public_profile, email'});
    }

    function getUserInfo() {
        FB.api('/me?fields=name,email,first_name,last_name', function(response) {
            console.log('Nome:, ' + response.name + '!');
            console.log('ID: ' + response.id + '!');
            console.log('Email: ' + response.email + '!');
            console.log('Primeiro Nome: ' + response.first_name + '!');
            console.log('Segundo Nome: ' + response.last_name + '!');
            $('#userProfileName').html(response.name);
        });
    }

    function getPhoto(){
        FB.api('/me/picture?type=normal', function(response) {
            $('#userProfilePicture').attr('src', response.data.url);
        })
    }

    function Logout() {
        FB.logout(function(response) {
            window.location.reload();
        });
    }

</script>

0 个答案:

没有答案