FriendsOfSymfony/FOSFacebookBundle — pull request #71 by ohFRY (2011-10-12 13:25:36+00:00)
Title: fixed: How-to set up the Facebook JavaScript SDK.

This PR is fixing the following still Open PR by updating the **README.md** with better explainations:
https://github.com/FriendsOfSymfony/FOSFacebookBundle/pull/36

The common error was (I had this too, that's why I wanted to fix it):
*The result is following javascript error message (Firefox 4): "FB is not defined".*

The error was to use

{{ facebook_initialize({'xfbml': true}) }}

when we should use

{{ facebook_initialize({'xfbml': true, 'fbAsyncInit': 'onfbinit();'}) }}

with this Javascript script:

function onfbinit() {
if (typeof(FB) != 'undefined' && FB != null ) {
FB.Event.subscribe('auth.login', function(response) {
window.location = "{{ path('_security_check') }}";
});
FB.Event.subscribe('auth.logout', function(response) {
window.location = "{{ path('_security_logout') }}";
});
}
}

The thing is : everytime you call "FB" in Javascript it requires FB.init() done. So each call of "FB" functions has to be called just after FB.init(). This can be done through the parameter **fbAsyncInit**