Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Login button: doesn't work when user is logged in Facebook

edit: explanation: When Facebook login button should appear and when not? On facebook tutorial page it is not accurately explained. There is written: "If the user is already logged in, no login button is shown". But for me, it is true only when user is logged in both in facebook profile and my facebook application connected to my website! It is not true, that button is removed when you are logged in just on facebook profile, as it is mentioned on the facebook tutorial. Am I right? –

could anybodey help? thanks tomas

//old message I have Facebook login button on my website. Sometime visitors are logged in facebook byt are not logged into my website (my application on fb). In this case, Login buton is displayed but does nothing. As I know, Login button should not only log in facebook but also login to my application.

It works OK when user is logged out both from facebook and application (website) before clicked. But what if user is logged in just to facebook? Then my button does nothing.

like image 931
tomas.teicher Avatar asked Dec 07 '25 06:12

tomas.teicher


1 Answers

You can render a button for connect session and another for those with out session.

Sample Usage: Using getLoginStatus() to determane if user is connected to app, and XFBML.parse to render the button. https://developers.facebook.com/docs/reference/javascript/FB.getLoginStatus/ I opted out of using channelURL but you can create your own and read about here. https://developers.facebook.com/docs/reference/javascript/

  1. if user is connected and logged in, logout button appears.
  2. if user is not connect but logged into facebook login button appears.
  3. if no session or login login button appears.

Async JavaScript SDK

<div id="fb-root"></div>
<!-- build1 is where we render our button based on connected status. -->
<div id="build1"></div>
<script>
      window.fbAsyncInit = function() {
        FB.init({
    appId  : 'YourAppId',
    status : true, // check login status
    cookie : true, // enable cookies to allow the server to access the session
    xfbml  : true, // parse XFBML
    //channelUrl : 'http://WWW.MYDOMAIN.COM/channel.html', // channel.html file
    oauth  : true // enable OAuth 2.0
        });
        if (window!=window.top) { 
        FB.Canvas.setAutoResize();
            }
            FB.getLoginStatus(function(response) {
            if (response.authResponse) {
            // logged in and connected user, someone you know
            // render button
            Cbuild1 = document.getElementById('build1');
            Cbuild1.innerHTML = "";
        Cbuild1.innerHTML = "<fb:login-button autologoutlink=\"true\"></fb:login-button>";
            FB.XFBML.parse(Cbuild1);
            } else {
            // no user session available, someone you dont know
            // render button
            Cbuild1 = document.getElementById('build1');
            Cbuild1.innerHTML = "";
        Cbuild1.innerHTML = "<fb:login-button></fb:login-button>";
            FB.XFBML.parse(Cbuild1);
            }
          });

      };
      (function() {
        var e = document.createElement('script'); e.async = true;
        e.src = document.location.protocol +
          '//connect.facebook.net/en_US/all.js';
        document.getElementById('fb-root').appendChild(e);
      }());
</script>

functionality of loginStatus tested here https://shawnsspace.com/fb.test.connect.loginbutton.php

like image 57
2 revsShawn E Carter Avatar answered Dec 08 '25 19:12

2 revsShawn E Carter



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!