2

I try to install FOSFacebook, I have follow all the steps, but i got this error in js console:

Uncaught ReferenceError: onFbInit is not defined

I have include this lignes in my base.html.twig:

    <!-- FaceBook Init -->
    {{ facebook_initialize({'xfbml': true, 'fbAsyncInit': 'onFbInit();'}) }}
    {{ facebook_login_button({'autologoutlink': true}) }}

    <script>
    $(document).ready(function() {
        function goLogIn(){
          window.location = "{{ path('_security_check') }}";
        }

        function onFbInit() {
          if (typeof(FB) != 'undefined' && FB != null ) {
              FB.Event.subscribe('auth.statusChange', function(response) {
                  if (response.session || response.authResponse) {
                      setTimeout(goLogIn, 500);
                  } else {
                      window.location = "{{ path('_security_logout') }}";
                  }
              });
          }
        }
    });
    </script>

Someone can help me? Thx

CdWeb
  • 43
  • 2

1 Answers1

0

Don´t define those functions within your $(document).ready(function() call. Use:

<script>
    function goLogIn(){
      window.location = "{{ path('_security_check') }}";
    }

    function onFbInit() {
      if (typeof(FB) != 'undefined' && FB != null ) {
          FB.Event.subscribe('auth.statusChange', function(response) {
              if (response.session || response.authResponse) {
                  setTimeout(goLogIn, 500);
              } else {
                  window.location = "{{ path('_security_logout') }}";
              }
          });
      }
    }
</script>
Carlos Granados
  • 11,273
  • 1
  • 38
  • 44
  • Ok, I try it and I have no more error but the button not appear, and I dont know why with out error... – CdWeb Sep 20 '12 at 09:14
  • Did you include the html markup? – Carlos Granados Sep 20 '12 at 09:17
  • Yes, when I look the iframe src generate by login button its a white page: http://www.facebook.com/plugins/login_button.php?api_key=123456879&auto_logout_link=true&channel=http%3A%2F%2Fstatic.ak.facebook.com%2Fconnect%2Fxd_arbiter.php%3Fversion%3D11%23cb%3Df31b95eb14%26origin%3Dhttp%253A%252F%252Flinkme.dev%252Ff304139dd8%26domain%3Dlinkme.dev%26relation%3Dparent.parent&locale=fr_FR&login_text=&scope=email&sdk=joey – CdWeb Sep 20 '12 at 09:24