how to get logout url in Facebook C# SDK?

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-24 16:57:52

问题


I tried this:

 public string GetLogoutUrl()
        {
            return String.Format("https://www.facebook.com/logout.php?next=http%3A%2F%2Fwww.google.com.br&access_token={0}", result.AccessToken);
        }

then:

webBrowser.Navigate(GetLogoutUrl());

Not worked. The user is redirected to facebook home page and not do logout.

how I do this? Thanks in advance.


回答1:


Also make sure the next url is belongs to your site url specified in the fb app settings.

next=http%3A%2F%2Fwww.google.com.br



回答2:


Home page here I assume it as facebook's login page. If you are not logged in then it would redirect you to the login page.

If the Home page is the profile page then it would redirect you to the home page which is valid because facebook's logout is a form submit and you cannot do it using webBrowser.Navigate(url).




回答3:


I am not familiar with FB. Maybe this code can work for you

StringBuilder sb = new StringBuilder();

HtmlElement form = webBrowser.Document.GetElementById("logout_form");
HtmlElementCollection inputs = form.GetElementsByTagName("input");
foreach (HtmlElement input in inputs)
{
    if (input.GetAttribute("name") != "")
    {
        sb.Append(input.GetAttribute("name") + "=" + input.GetAttribute("value") + "&");
    }
}
sb.Length--;


WebClient www = new WebClient();
www.Headers["Cookie"] = webBrowser.Document.Cookie;
www.Headers["User-Agent"] = "Mozilla/5.0 (Windows NT 5.1) AppleWebKit/535.2 (KHTML, like Gecko) Chrome/15.0.874.121 Safari/535.2";
www.Headers["Content-Type"] = "application/x-www-form-urlencoded";
www.Headers["Accept"] = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
webBrowser.DocumentText = www.UploadString("http://www.facebook.com/logout.php/", sb.ToString());



回答4:


Why dont u just issue a POST via HttpWebRequest? it seems more cleaner



来源:https://stackoverflow.com/questions/8261568/how-to-get-logout-url-in-facebook-c-sharp-sdk

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