Atualização em 04 de janeiro de 2012
Parece que você não pode simplesmente chamar métodos dependentes de FB (por exemplo FB.getAuthResponse()) logo depois FB.init()como antes, pois FB.init()parece ser assíncrono agora. Encapsular seu código em uma FB.getLoginStatus()resposta parece funcionar para detectar quando a API está totalmente pronta:
window.fbAsyncInit = function() {
FB.init({
//...
});
FB.getLoginStatus(function(response){
runFbInitCriticalCode();
});
};
ou se estiver usando a fbEnsureInit()implementação abaixo:
window.fbAsyncInit = function() {
FB.init({
//...
});
FB.getLoginStatus(function(response){
fbApiInit = true;
});
};
Postagem original:
Se você quiser apenas executar algum script quando o FB for inicializado, você pode colocar alguma função de retorno de chamada dentro 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
};
Se você deseja uma substituição exata de FB.ensureInit, então você terá que escrever algo por conta própria, pois não há uma substituição oficial (grande erro, imo). Aqui está o que eu uso:
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();
}
}
}
Uso:
fbEnsureInit(function() {
console.log("this will be run once FB is initialized");
});