Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<h2>I've avoided using setTimeout by using a global function:</h2> <p>EDIT NOTE: I've updated the following helper scripts and created a class that easier/simpler to use; check it out here ::: <a href="https://github.com/tjmehta/fbExec.js" rel="nofollow">https://github.com/tjmehta/fbExec.js</a></p> <pre><code>window.fbAsyncInit = function() { FB.init({ //... }); window.fbApiInit = true; //init flag if(window.thisFunctionIsCalledAfterFbInit) window.thisFunctionIsCalledAfterFbInit(); }; </code></pre> <p>fbEnsureInit will call it's callback after FB.init</p> <pre><code>function fbEnsureInit(callback){ if(!window.fbApiInit) { window.thisFunctionIsCalledAfterFbInit = callback; //find this in index.html } else{ callback(); } } </code></pre> <p>fbEnsureInitAndLoginStatus will call it's callback after FB.init and after FB.getLoginStatus</p> <pre><code>function fbEnsureInitAndLoginStatus(callback){ runAfterFbInit(function(){ FB.getLoginStatus(function(response){ if (response.status === 'connected') { // the user is logged in and has authenticated your // app, and response.authResponse supplies // the user's ID, a valid access token, a signed // request, and the time the access token // and signed request each expire callback(); } else if (response.status === 'not_authorized') { // the user is logged in to Facebook, // but has not authenticated your app } else { // the user isn't logged in to Facebook. } }); }); } </code></pre> <h2>fbEnsureInit example usage:</h2> <p>(FB.login needs to be run after FB has been initialized)</p> <pre><code>fbEnsureInit(function(){ FB.login( //..enter code here ); }); </code></pre> <h2>fbEnsureInitAndLogin example usage:</h2> <p>(FB.api needs to be run after FB.init and FB user must be logged in.)</p> <pre><code>fbEnsureInitAndLoginStatus(function(){ FB.api( //..enter code here ); }); </code></pre>
 

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