问题
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