Reputation: 83
I'm using Facebook's Javascript SDK to allow login/logout, and my problem is that when I use their window.fbAsyncInit call to initiate the FB session, it always fires twice. I've included a simplified code sample. I'd appreciate any help!
In the code below, the "2" alert fires a single time, and then the "1" alert fires twice.
<html><head>
<script type="text/javascript">
...some of my own functions, not related to Facebook...
</script>
</head>
<body>
<div id="fb-root"></div>
<script>
window.fbAsyncInit = function() {
FB.init({
appId : '<?php echo FACEBOOK_APPID; ?>',
session : <?php echo json_encode($session); ?>, status:false, cookie:true, xfbml: true
});
alert("1");
FB.getLoginStatus(function(response) {
if(response.session) { ...do stuff... } else { ...do other stuff...}
});
};
alert("2");
(function() {
var e = document.createElement('script');
e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js';
e.async = true;
document.getElementById('fb-root').appendChild(e);
}());
</script>
...page contents...
</body></html>
Upvotes: 4
Views: 2806
Reputation: 5092
You might accidentally be including two different Facebook javascripts.
Upvotes: 5