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.
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/
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With