How to get Facebook Login Button To Display "Logout"

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

I've implemented the FB login button on a website using GAE + Python. Here is the 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?

Answers


Its not documented on the FB SDK login-button page for 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: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>

Thanks to user "haha" the solution is:

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


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


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

<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


Need Your Help

Ext JS library not installed correctly in Oozie

hadoop oozie hortonworks-data-platform ambari

I'm getting the following message when I access to the oozie UI.

Best way to dynamically set an appender file path

c# log4net

I am trying to find somebody smarter than me to validate some syntax I wrote up. The idea is to configure the filename of my RollingFileAppender to the name of the assembly in order to make it mor...