Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FB Logout with C# sdk

I'm logged in to my app using my FB credentials. In the end I do a logout and remove my session variables. I'm logged out from application, but the FB session remains open although I do a post to the FB logout page with the post like in the code:

if (Session["FBAccessToken"] != null){

  var fb = new Facebook.FacebookClient();
  string accessToken = Session["FBAccessToken"] as string;
  //var logoutUrl = fb.GetLogoutUrl(new { access_token = accessToken, next = "https://www.facebook.com/", });
  var logoutUrl = fb.GetLogoutUrl(new {  next = "https://www.facebook.com/", });

  fb.Post(logoutUrl.AbsoluteUri, new { access_token = accessToken });
  Session.RemoveAll();
}

I've tried both: logoutUrl generated with and without access token parameter, neither worked for me.

like image 733
Biljanka Avatar asked Oct 29 '12 07:10

Biljanka


1 Answers

There has been changes on facebook logout since my last blog post. Here is the way to logout.

var fb = new FacebookClient();
var logoutUrl = fb.GetLogoutUrl(new {access_token = "...", next = "...." });

// redirect to logoutUrl.AbsoluteUri

next url cannot be any arbitrary url. I has to be the one that is part of the site url which you used to retrieve the access token.

like image 150
prabir Avatar answered Sep 18 '22 11:09

prabir