Facebook fbAsyncInit shoots twice

I use the Facebook Javascript SDK to allow login / logout, and my problem is that when I use their call to window.fbAsyncInit to initiate an FB session, it always fires twice. I included a simplified sample code. I would be grateful for any help!

In the code below, warning “2” is triggered once, and then warning “1” is triggered 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> 
+4
source share
1 answer

You might accidentally enable two different Facebook javascripts.

+5
source

Source: https://habr.com/ru/post/1334032/


All Articles