Dofs
Dofs

Reputation: 19197

Logout with facebook

How can I log a user out from my facebook connect website, without using the fb-login button? I would like to do it from codebehind (c#)?

Upvotes: 8

Views: 69717

Answers (8)

John Starr Dewar
John Starr Dewar

Reputation: 1371

If you just want a simple link to log out the user, you can form a url like this:

https://www.facebook.com/logout.php?access_token=ACCESS_TOKEN&confirm=1&next=REDIRECT

Just replace ACCESS_TOKEN and REDIRECT with the appropriate values. Facebook changes this every now and then, so you have to watch out for that. This only works in the browser, but the nice thing about doing it this way is that the user doesn't have to wait for the JavaScript library to load.

Upvotes: 7

Dofs
Dofs

Reputation: 19197

I found out that there was only an option to do it from Javascript by FB.logout(). It seems kinda wird that there is no API from codebehind to do the same.

Upvotes: 10

Blundell
Blundell

Reputation: 76458

I was doing this in a Webview using:

 webview.loadUrl("http://www.facebook.com/logout.php?confirm=1");

Upvotes: 0

prabir
prabir

Reputation: 7794

seems ConnectSession doesn't have any codes in Logout methd. Its just

void Logout(){ }

without anything. same for Login(){}

so basically you will need to use the java-script version

Upvotes: 2

Michael
Michael

Reputation: 11

Isn't it possible with curl and something like preg_match("/a href=\"\/logout.php(.*?)\"/", $page, $logout_param);

then...

curl_setopt($ch, CURLOPT_URL, 'http://m.facebook.com/logout.php' . $logout_param[1]); curl_exec($ch);

??

Upvotes: 1

Stephane
Stephane

Reputation: 21

My painful experience showed me you MUST have a return(false); after the FB.Connect.logout(); call like in :

FB.Connect.logout(doOnUserLogout()); return(false);

Otherwise it'll seem like it is logging out, with the modal dialog box stating so, but it will not log the user out.

I found this out by chance as it was again not documented.

Upvotes: 2

Ruslan
Ruslan

Reputation:

You can easily do this from an instance of the facebook.API class(facebook.dll). Just call _api.LogOff()

Upvotes: 3

Mon Villalon
Mon Villalon

Reputation: 692

At least in the php api there is a logout method. In order for it to work the logout method redirects the user to an url in facebook.com and then redirects you back to your site

$facebook->logout( "http://site.com/returnAfterLogout.php" )

However i have found that in that request the javascript api still thinks the php api still thinks he is logged in and until you try to do an api request it will raise an exception.

Upvotes: 0

Related Questions