如何从Asp.net注销Facebook?

时间:2012-08-21 08:20:08

标签: asp.net .net facebook facebook-c#-sdk

我使用以下代码使用我的Asp.net应用程序登录Facebook。

我能够完美登录......但我如何从FB退出?

<input type="button" id="fblogin" value="Login to Facebook" disabled="disabled" style="display: none" />
<fb:login-button v="2" autologoutlink='true' length="long" onlogin="$('#fblogin').click()">Login to Facebook</fb:login-button>  

<script>
    window.fbAsyncInit = function () 
    {
        FB.init({
            appId: '<%: Facebook.FacebookApplication.Current.AppId %>',
            cookie: true,
            xfbml: true,
            oauth: true
        });

        function facebooklogin() {
            FB.login(function (response) {
                if (response.authResponse) {
                    // user authorized
                    // make sure to set the top.location instead of using window.location.reload()
                    top.location = '<%= this.ResolveCanvasPageUrl("~/") %>';
                } else {
                    // user cancelled
                }
            }, { scope: '<%: string.Join(",", ExtendedPermissions) %>' });
        };

        $(function () {
            // make the button is only enabled after the facebook js sdk has been loaded.
            $('#fblogin').attr('disabled', false).click(facebooklogin); });
        });

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

2 个答案:

答案 0 :(得分:2)

这有效......

https://www.facebook.com/logout.php?     接下来= YOUR_REDIRECT_URL    &安培; =的access_token USER_ACCESS_TOKEN

答案 1 :(得分:1)

使用此代码

<div id="user-info"></div>
<p><button id="fb-auth">Login using facebook</button></p>



<script type="text/javascript">
    window.fbAsyncInit = function () {
        FB.init({ appId: 'appid',
            status: true,
            cookie: true,
            xfbml: true,
            oauth: true
        });

        function updateButton(response) {
            var button = document.getElementById('fb-auth');

            if (response.authResponse) {
                //user is already logged in and connected
                var userInfo = document.getElementById('user-info');
                FB.api('/me', function (response) {
                    userInfo.innerHTML = '<img src="https://graph.facebook.com/'
      + response.id + '/picture">' + response.name + response.email;
                    button.innerHTML = 'Logout';



                });
                button.onclick = function () {
                    FB.logout(function (response) {
                        var userInfo = document.getElementById('user-info');
                        userInfo.innerHTML = "";
                        //to textbox
                        document.getElementById('TxtFname').value = "";
                        document.getElementById('Txtemail').value = "";
                    });
                };
            } else {
                //user is not connected to your app or logged out
                button.innerHTML = 'Login using facebook';
                button.onclick = function () {
                    FB.login(function (response) {
                        if (response.authResponse) {
                            FB.api('/me', function (response) {
                                var userInfo = document.getElementById('user-info');
                                userInfo.innerHTML =
                '<img src="https://graph.facebook.com/'
            + response.id + '/picture" style="margin-right:5px"/>'
            + response.name + "emailid" + response.email;
                            });
                        } else {
                            //user cancelled login or did not grant authorization
                        }
                    }, { scope: 'email' });
                }
            }
        }

        // run once with current status and whenever the status changes
        FB.getLoginStatus(updateButton);
        FB.Event.subscribe('auth.statusChange', updateButton);
    };

    (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>