Logging out from facebook using facebook c# sdk in WP7

大城市里の小女人 提交于 2019-12-19 11:05:55

问题


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.



来源:https://stackoverflow.com/questions/11558603/logging-out-from-facebook-using-facebook-c-sharp-sdk-in-wp7

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!