Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>Update on Jan 04, 2012</strong></p> <p>It seems like you can't just call FB-dependent methods (for example <code>FB.getAuthResponse()</code>) right after <code>FB.init()</code> like before, as <code>FB.init()</code> seems to be asynchronous now. Wrapping your code into <code>FB.getLoginStatus()</code> response seems to do the trick of detecting when API is fully ready:</p> <pre><code>window.fbAsyncInit = function() { FB.init({ //... }); FB.getLoginStatus(function(response){ runFbInitCriticalCode(); }); }; </code></pre> <p>or if using <code>fbEnsureInit()</code> implementation from below:</p> <pre><code>window.fbAsyncInit = function() { FB.init({ //... }); FB.getLoginStatus(function(response){ fbApiInit = true; }); }; </code></pre> <hr> <p><strong>Original Post:</strong></p> <p>If you want to just run some script when FB is initialized you can put some callback function inside <code>fbAsyncInit</code>:</p> <pre><code> window.fbAsyncInit = function() { FB.init({ appId : '&lt;?php echo $conf['fb']['appid']; ?&gt;', 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 }; </code></pre> <p>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:</p> <pre><code> window.fbAsyncInit = function() { FB.init({ appId : '&lt;?php echo $conf['fb']['appid']; ?&gt;', 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(); } } } </code></pre> <p>Usage:</p> <pre><code>fbEnsureInit(function() { console.log("this will be run once FB is initialized"); }); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload