just leave your function queue and then call it immediately after initializing the FB. The following code ensures that your functions will be called in the correct order, and immediately after completing FB initialization
you include the helper script BEFORE THIS EXAMPLE and before starting the FB script:
var FB; // to avoid error "undeclared variable", until FB got initialized var myQueue = new Array(); function queueAdd(f){ if (FB == undefined) myQueue.push(f); else f(); } function processQueue(){ var f; while(f = myQueue.shift()) f(); }
your function example:
function example(){ FB.api( '/me/[namespace]:visit', 'post', { channel: link}, function(response) { if (!response || response.error) { console.log(response.error); } else { console.log('Follow was success! Action ID: ' + response); } }); } queueAdd(example);
and part of FB:
window.fbAsyncInit = function() { FB.init(blablabla); processQueue(); }
source share