C# 用脸书登出

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/658027/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-04 12:10:06  来源:igfitidea点击:

Logout with facebook

c#.netfacebook

提问by Dofs

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#)?

如何在不使用 fb-login 按钮的情况下将用户从我的 facebook 连接网站注销?我想从代码隐藏 (c#) 中做到这一点?

采纳答案by Dofs

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.

我发现只有一个选项可以通过 Javascript 从FB.logout(). 代码隐藏中没有 API 来做同样的事情,这似乎有点奇怪。

回答by Mon Villalon

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

至少在 php api 中有一个注销方法。为了使其工作,注销方法会将用户重定向到 facebook.com 中的 url,然后将您重定向回您的站点

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

$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.

但是我发现在该请求中,javascript api 仍然认为 php api 仍然认为他已登录,并且在您尝试执行 api 请求之前,它会引发异常。

回答by Mon Villalon

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

您可以通过 facebook.API 类 (facebook.dll) 的实例轻松完成此操作。只需调用 _api.LogOff()

回答by Stephane

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

我的痛苦经历告诉我你必须有一个回报(假);在 FB.Connect.logout() 之后;像这样调用:

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

FB.Connect.logout(doOnUserLogout()); 返回(假);

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.

我偶然发现了这一点,因为它再次没有记录。

回答by prabir

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

似乎 ConnectSession 在注销方法中没有任何代码。只是

void Logout(){ }

without anything. same for Login(){}

没有任何东西。同样的Login(){}

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

所以基本上你需要使用java-script版本

回答by Michael

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

curl 和类似 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);

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

??

??

回答by Blundell

I was doing this in a Webview using:

我正在使用以下方法在 Webview 中执行此操作:

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

回答by John Starr Dewar

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

如果你只是想要一个简单的链接来注销用户,你可以像这样形成一个 url:

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

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

Just replace ACCESS_TOKENand REDIRECTwith 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.

只需将ACCESS_TOKEN和替换REDIRECT为适当的值。Facebook 时不时地改变这一点,所以你必须注意这一点。这仅适用于浏览器,但这样做的好处是用户不必等待 JavaScript 库加载。