Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1016985
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T10:37:57+00:00 2026-05-16T10:37:57+00:00

The old JS SDK had a function called FB.ensureInit. The new SDK does not

  • 0

The old JS SDK had a function called FB.ensureInit. The new SDK does not seem to have such function… how can I ensure that I do not make api calls until it is fully initiated?

I include this in the top of every page:

<div id="fb-root"></div>
<script>
  window.fbAsyncInit = function() {
    FB.init({
      appId  : '<?php echo $conf['fb']['appid']; ?>',
      status : true, // check login status
      cookie : true, // enable cookies to allow the server to access the session
      xfbml  : true  // parse XFBML
    });
    FB.Canvas.setAutoResize();
  };

  (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>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T10:37:58+00:00Added an answer on May 16, 2026 at 10:37 am

    Update on Jan 04, 2012

    It seems like you can’t just call FB-dependent methods (for example FB.getAuthResponse()) right after FB.init() like before, as FB.init() seems to be asynchronous now. Wrapping your code into FB.getLoginStatus() response seems to do the trick of detecting when API is fully ready:

    window.fbAsyncInit = function() {
        FB.init({
            //...
        });
    
        FB.getLoginStatus(function(response){
            runFbInitCriticalCode(); 
        });
    
    };  
    

    or if using fbEnsureInit() implementation from below:

    window.fbAsyncInit = function() {
        FB.init({
            //...
        });
    
        FB.getLoginStatus(function(response){
            fbApiInit = true;
        });
    
    };  
    

    Original Post:

    If you want to just run some script when FB is initialized you can put some callback function inside fbAsyncInit:

      window.fbAsyncInit = function() {
        FB.init({
          appId  : '<?php echo $conf['fb']['appid']; ?>',
          status : true, // check login status
          cookie : true, // enable cookies to allow the server to access the session
          xfbml  : true  // parse XFBML
        });
        FB.Canvas.setAutoResize();
    
        runFbInitCriticalCode(); //function that contains FB init critical code
      };
    

    If you want exact replacement of FB.ensureInit then you would have to write something on your own as there is no official replacement (big mistake imo). Here is what I use:

      window.fbAsyncInit = function() {
        FB.init({
          appId  : '<?php echo $conf['fb']['appid']; ?>',
          status : true, // check login status
          cookie : true, // enable cookies to allow the server to access the session
          xfbml  : true  // parse XFBML
        });
        FB.Canvas.setAutoResize();
    
        fbApiInit = true; //init flag
      };
    
      function fbEnsureInit(callback) {
            if(!window.fbApiInit) {
                setTimeout(function() {fbEnsureInit(callback);}, 50);
            } else {
                if(callback) {
                    callback();
                }
            }
        }
    

    Usage:

    fbEnsureInit(function() {
        console.log("this will be run once FB is initialized");
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I had code in a old sdk 3.0 project of mine that is not
I'm using a new work computer that has an old sdk, Java 1.3.1, on
Scenario: old legacy code in rpg have to consume data from a new web
I have an application that uses the new features of honeycomb for the PreferenceActivity.
This had been driving me crazy.... I have an iPhone app that is using
Currently I am developing Android project for old sdk version. However - new SDK
I recently installed the new Windows Mobile 6.5.3 SDK upgrading my old Windows Mobile
Can you build Mac SDK 10.7 applications without having Mac SDK 10.7? Such as
I've been using the old v3.0 C# SDK for some time and Facebook have
I had updated my android sdk to ics(4.1) as i updated all my old

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.