facebook session check on login
I have put the following code in my head to check the session:
<script type="text/javascript">
FB.getLoginStatus(function(response) {
if (response.session) {
alert('I am logged in');
} else {
alert('I am logged out');
开发者_JAVA百科 }
});
</script>
however, it does not get executed on page load, why is this?
Make sure you have:
FB.init({
appId : APP_ID, // Your FB app ID from www.facebook.com/developers/
status : true, // check login status
cookie : true, // enable cookies to allow the server to access the session
xfbml : true // parse XFBML
});
before any other FB reference in your scripts (using window.onload or similar) and
<DIV id="fb-root"></div>
in the <body>
section.
精彩评论