1
votes

I am developing a Facebook WPF application for my senior design project in college. I've never coded in C# or developed a WPF application before this. Right now I'm trying to implement logout functionality. I'm using a WebBrowser to do this, and the documentation seems to say that the method of doing this is to navigate to:

https://www.facebook.com/logout.php?next={redirectURI}&access_token={token}

in the browser, where the sections in curly braces are variables. For some reason, it brings me back to the Facebook home page (news feed) every time I do this. Is this due to a change made by Facebook in recent years or is there an error on my part? Alternative methods of logging out via a web browser, such as an alternative logout URL, would be appreciated as well.

1
Do you have that redirect URI set somewhere in your app settings? It doesn't have to be as strictly specified as the actual redirect_uri parameter used during login, but it should at least match or be below the URL you have specified for the Website platform. - CBroe
In the advanced app settings, the redirect uri itself and "facebook.com/logout.php" are both added in the domain manager. I'm not sure what else would need to be changed. - Laci Felker

1 Answers

1
votes

With FB SDK V6, there are some nuances. I'll delve into a few things you need to verify in your code. Your code probably would've worked with previously, but today you should make the following changes, assuming you haven't already:

  1. The redirectURI in your code needs to be changed to "http://www.facebook.com". Standard redirect URIs (including those associated with your access token generation) don't seem to work anymore.

  2. You also need to make sure your redirectURI is an absolute URI. There is a very simple way to do this, which I will show in the code below.

Bringing it together, this code will work for the current FB C# SDK via a WebBrowser:

var fb = new FacebookClient();
var logoutURL = fb.GetLogoutUrl(new { access_token = {userAccessToken}, next = "https://www.facebook.com/"});
WebBrowser1.Navigate(logoutURL.AbsoluteUri);

A final note is that in my code, I chose to ask for the logoutURL instead of hardcoding it. It looks like after making the changes your logoutURL would still be correct, but it may be beneficial to retrieve the url to help ensure correctness. Good luck on your project.