Facebook SDK for .NET login, exit code

I used the Button Button Button Control in the Facebook SDK for .NET in the application, and I need to change the status / state of the button of the login button from "Logout" to "Login", that is, I need to manually log out the user through the code.

How is this possible?

+2
source share
3 answers

Use FacebookClient.Logoutto create exit URL.

This is just a sample.

private void btnLogout_Click(object sender, EventArgs e)
{
    var fb = new FacebookClient();

    var logoutUrl = fb.GetLogoutUrl(new
                                        {
                                            next =    "https://www.facebook.com/connect/login_success.html",
                                            access_token = _accessToken
                                        });
    var webBrowser = new WebBrowser();
    webBrowser.Navigated += (o, args) =>
                                {
                                    if (args.Url.AbsoluteUri == "https://www.facebook.com/connect/login_success.html")
                                        Close();
                                };

    webBrowser.Navigate(logoutUrl.AbsoluteUri);
}

Be sure to save access tokensomewhere at login so you can also use it to log out.

+3
source

, cookie Facebook WebBrowser.

Facebook, WebBrowser.

, cookie Windows Phone 7.

Windows Phone 8 ClearCookiesAsync

await new WebBrowser().ClearCookiesAsync();

, :

Facebook Windows Phone Application

+1

I spent many hours trailing to get this. Thanks a lot Kulasangar

I modified your code a bit, but it works:

var identity = AuthenticationManager.GetExternalIdentity(DefaultAuthenticationTypes.ExternalCookie);
var accessToken = identity.FindFirstValue("FacebookAccessToken");
var fb = new FacebookClient(accessToken);

var logoutUrl = fb.GetLogoutUrl(new
                {
                    next = "https://www.facebook.com/connect/login_success.html",
                    access_token = accessToken
                });
Response.Redirect(logoutUrl.AbsoluteUri);
0
source

All Articles