0

I have this script that I put on the head section of my html:

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

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

So the alert box here is printed out. However I tried logging in and logging out, but none of the login or logout is triggered. Any idea why?

Here's how I initialized the facebook button:

<!-- inside a twig template -->
{{ facebook_initialize({'xfbml': true, 'fbAsyncInit': 'onFbInit();'}) }}

{{ facebook_login_button({'autologoutlink': true, 'label': 'Log in using Facebook'}) }}
xonegirlz
  • 8,889
  • 19
  • 69
  • 127
  • Is `"{{ path('_security_logout') }}"` being interpolated by Twig? – pdoherty926 Sep 15 '12 at 04:59
  • @ethagnawl mind clarifying what interpolated mean? the thing is that it didn't even print the alert, either login or logout – xonegirlz Sep 15 '12 at 05:05
  • Does Twig turn `{{ path('_security_logout') }}` into a string? Are there any errors in the console? Have you tried placing an `alert` inside the `'auth.statusChange'` callback, but outside the `if`? – pdoherty926 Sep 15 '12 at 05:10
  • @ethagnawl yes and it didn't print the alert as well – xonegirlz Sep 15 '12 at 05:12
  • What is the value of `FB` inside `onFbInit`? Have you included the facebook.js script on the page? – pdoherty926 Sep 15 '12 at 05:15
  • @ethagnawl how do I print the value of FB? – xonegirlz Sep 15 '12 at 05:15
  • and yes I did initialize it using {{ facebook_initialize({'xfbml': true, 'fbAsyncInit': 'onFbInit();'}) }} – xonegirlz Sep 15 '12 at 05:16
  • If your browser has a console, `console.log(FB)` otherwise `alert(JSON.stringify(FB))`. – pdoherty926 Sep 15 '12 at 05:17
  • Yea, it gives me {"_callbacks":{},"Array":{},"EventProvider":{},"Event":{},"Canvas":{"Prefetcher":{}},"CanvasInsights":{},"UA":{},"Content":{},"Arbiter":{},"String":{},"Dom":{},"Intl":{},"Type":{},"XD":{},"Dialog":{},"QS":{},"JSON":{},"UIServer":{"MobileIframableMethod":{},"Methods":{}},"Auth":{},"URI":{},"XFBML":{"IframeWidget":{},"ConnectBar":{},"EdgeCommentWidget":{},"Send":{},"ProfilePic":{}},"Data":{},"Frictionless":{},"Cookie":{},"Native":{},"Helper":{},"TemplateData":{},"TemplateUI":{},"Anim":{},"Insights":{}} – xonegirlz Sep 15 '12 at 05:23
  • Sorry, but I have to call it a night. [Something else to consider.](http://stackoverflow.com/questions/5133075/running-facebook-application-on-localhost) – pdoherty926 Sep 15 '12 at 05:38
  • Your code is correct (I have the exact same setup). Must be some configuration issue, either of the FOSFacebookBundle or of your Facebook app. Try this: log out of facebook.com and press your facebook login button. What happens? You should see a pop up dialog asking you to log into Facebook. – Carlos Granados Sep 15 '12 at 08:15
  • @CarlosGranados yes, I can see the log into Facebook dialog.. I can log in.. and then the login button turns into logout – xonegirlz Sep 15 '12 at 14:52
  • But the goLogin function() is not called? – Carlos Granados Sep 15 '12 at 15:35

1 Answers1

0

It turns out that I have to clear the cookies and then it worked.

xonegirlz
  • 8,889
  • 19
  • 69
  • 127