FB.init is already called

I am creating a facebook iframe application. My application loads once (I get signed_request once) and then I browse the pages in the iframe using the internal domain links. I noticed that I see these strange messages in both Chrome and Firefox

FB.init has already been called - this could indicate a problem 

I am sure that this method is called only once, and it seems that Facebook wants me to call it once to download the application (not once per page).

 window.fbAsyncInit = function() { FB.init({ appId: param('facebook_app_id'), frictionlessRequests: true, oauth: true, channelUrl: site_url('/channel.html') }) } 

What mistake (if any) am I making here?

+53
facebook opengraph
May 2 '12 at 2:33
source share
3 answers

From the moment the parameters are js.src to js.src , as #xfbml=1&appId=X , the FB SDK will automatically initialize itself and thus the FB.init will try to reinstall. Therefore, in your code you do not need to remove the FB.init function, just make sure you are not passing parameters in code that asynchronously loads the JS SDK.

Replace this:

 js.src = "//connect.facebook.net/en_US/sdk.js#xfbml=1&appId=X"; 

Via:

 js.src = "//connect.facebook.net/en_US/sdk.js"; 

Hope this helps.

+158
May 2 '12 at 20:38
source share

If you really need to call init more than once, you can do this:

 FB._initialized = false; FB.init(); 

but it doesn't make sense to me, I have a slightly different problem, but it is also related to the FB.init has already been called - this could indicate a problem message. FB.init has already been called - this could indicate a problem .

I have an AJAX-based website where, after each page load, I need to display XFBML from the HTML that I get from the AJAX request (comments like a button and more):

  <div class="fb-comments" data-href="{REMOVED}" data-num-posts="5" data-width="760" colorscheme="dark"></div> 

To do this, you can run this when you need to display XFBML:

 FB.XFBML.parse(); 
+10
May 02 '12 at 19:38
source share

I also had this problem. I just deleted the part of FB.init({...}) and started working with the following code:

 window.fbAsyncInit = function () { FB.Event.subscribe('auth.logout', function () { // subscribe parts }); // here is where fb.init() code was }; (function(d, s, id) { var js, fjs = d.getElementsByTagName(s)[0]; if (d.getElementById(id)) return; js = d.createElement(s); js.id = id; js.src = "//connect.facebook.net/en_US/all.js#xfbml=1&appId=X"; fjs.parentNode.insertBefore(js, fjs); }(document, 'script', 'facebook-jssdk')); 

I think now it automatically enters the code, so there is no need to do it manually. Now my code is working again. Hope this helps.

0
May 2 '12 at 19:13
source share



All Articles