Python 如何让 Facebook 登录按钮显示“注销”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4522427/
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-18 16:06:36  来源:igfitidea点击:

How to get Facebook Login Button To Display "Logout"

javascriptpythonfacebookfacebook-graph-api

提问by Will Curran

I apologize ahead of time if this is clearly documented somewhere on the FB developer site - but I can't find it (so please link me if appropriate).

如果在 FB 开发人员网站上的某处清楚地记录了这一点,我会提前道歉 - 但我找不到它(所以请在适当的情况下链接我)。

I've implemented the FB login button on a website using GAE + Python. Here is the HTML:

我已经使用 GAE + Python 在网站上实现了 FB 登录按钮。这是 HTML:

<fb:login-button></fb:login-button>
<div id="fb-root"></div>
<script src="http://connect.facebook.net/en_US/all.js"></script>
<script>
  FB.init({appId: 'ad16a806fc10bef5d30881322e73be68', status: true, cookie: true, xfbml: true});
  FB.Event.subscribe('auth.sessionChange', function(response) {
    if (response.session) {
      // A user has logged in, and a new cookie has been saved
    } else {
      // The user has logged out, and the cookie has been cleared
    }
  });
</script>

Currently the behavior is - if I click on the "login" button, I am asked to allow the application access to FB. Which I then choose, "OK". But then the login button is still showing "login" and not "logout". How do I implement that? On the server or client side?

目前的行为是 - 如果我点击“登录”按钮,我会被要求允许应用程序访问 FB。然后我选择“确定”。但是登录按钮仍然显示“登录”而不是“注销”。我该如何实施?在服务器端还是客户端?

采纳答案by Will Curran

Thanks to user "haha" the solution is:

感谢用户“哈哈”,解决方案是:

1) Grab the Facebook Python SDK: https://github.com/facebook/python-sdk/tree/master/examples/appengine2) Implement the HTML example: https://github.com/facebook/python-sdk/blob/master/examples/appengine/example.html3) Update your main request handler and models: https://github.com/facebook/python-sdk/blob/master/examples/appengine/example.py

1) 获取 Facebook Python SDK:https: //github.com/facebook/python-sdk/tree/master/examples/appengine2) 实现 HTML 示例:https: //github.com/facebook/python-sdk/ blob/master/examples/appengine/example.html3) 更新您的主要请求处理程序和模型:https: //github.com/facebook/python-sdk/blob/master/examples/appengine/example.py

回答by Derek Dahmer

Its not documented on the FB SDK login-button pagefor some reason, but you can add the autologoutlink="true"attribute to the tag and it will show a logout button if you are logged in rather than just making the button invisible.

由于某种原因,它没有记录在 FB SDK登录按钮页面上,但是您可以将该autologoutlink="true"属性添加到标记中,如果您已登录,它会显示一个注销按钮,而不仅仅是使按钮不可见。

<fb:login-button autologoutlink="true"></fb:login-button>

Warning: it will ignore that tag if you are using custom text on the login button like

警告:如果您在登录按钮上使用自定义文本,它将忽略该标签,例如

<!-- This will always display the button, whether you are logged in or out -->
<fb:login-button autologoutlink="true">Login To My Service!</fb:login-button>

回答by J Starr

This has now been documented at https://developers.facebook.com/docs/reference/plugins/login/. You may also want to check out onloginfor your callback.

这现在已在https://developers.facebook.com/docs/reference/plugins/login/ 上记录。您可能还想查看onlogin您的回调。

回答by oabarca

Derek did not mentioned the HTML5 alternative which is he recommended way:

Derek 没有提到他推荐的 HTML5 替代方法:

<div id="fbloginbut" scope="user_birthday" onlogin="checkLoginState();" class="fb-login-button" data-max-rows="1" data-size="large" data-show-faces="false" data-auto-logout-link="true"></div>

The following page will generate the code for the login/logout button that you like the most: https://developers.facebook.com/docs/plugins/login-button

以下页面将生成您最喜欢的登录/注销按钮的代码:https: //developers.facebook.com/docs/plugins/login-button