Logging out from facebook using facebook c# sdk in

2020-03-30 06:29发布

问题:

I want to implement logout from facebook using facebook C# sdk in my windows phone app

My primary question is how do we logout using Facebook C# SDK in WP7

I found this article in search

Article link

there he is trying to find the logout url using regex, but that did not working in my app

when i try that the browser navigated event is going into infinite loop

you can share any samples/posts related to facebook logout in windows phone 7.

I want logout should happen with out user intervention, after he clicks on a button he should looged out from facebook and from next time he should see the login page

I tried following posts/blogs also but no use.

LINK 1

LINK 2 this giving error while splitting the accesstoken

UPDATE

LogOutButtonCode

 FacebookClient _fbClient = new FacebookClient(fbaccess.AccessToken);
        var logoutParams = new Dictionary<string, object>();
        logoutParams.Add("next", "https://www.facebook.com/connect/login_success.html");
        //logoutParams.Add("",)

        var logoutUrl = _fbClient.GetLogoutUrl(logoutParams);
        BrowserControl.Navigated += new EventHandler<System.Windows.Navigation.NavigationEventArgs>(BrowserControl_Navigated);

        BrowserControl.Navigate(new Uri(logoutUrl.AbsoluteUri));

Navigated Event CODE

if (e.Uri.AbsoluteUri == "https://www.facebook.com/connect/login_success.html")
        {


            NavigationService.Navigate(new Uri("/MainPage.xaml", UriKind.Relative));
        }

e.Uri.AbsoluteUri returns https://www.facebook.com/home.php

Logout URL i am getting from the server https://www.facebook.com/logout.php?next=https://www.facebook.com/connect/login_success.html

回答1:

Use FacebookClient.Logout to generate the logout url.

This is the snippet from winforms sample which will work in wp7 with some modifications.

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

Make sure to persist the access token somewhere when you login as it is required to logout.