Facebook login button works only on the second click

前端 未结 1 1938
余生分开走
余生分开走 2021-01-27 07:01

I\'m using the php facebook class and put a login button on my page with $f->getLoginUrl(), the problem is this button does not work at first time I click on it.

相关标签:
1条回答
  • 2021-01-27 07:08

    Have you added the standard FB handlers in your javascript portion? They are supposed to reload the page and set some cookies for the facebook API to work...

    <!-- FACEBOOK JAVASCRIPT HANDLER START -->
    <div id="fb-root"></div>
    <script>
        window.fbAsyncInit = function() {
            FB.init({
                appId: '%CONTEST_FACEBOOKAPPID%',
                cookie: true,
                xfbml: true,
                oauth: true
            });
            FB.Event.subscribe('auth.login', function(response) {
                window.location.reload();
            });
            FB.Event.subscribe('auth.logout', function(response) {
                window.location.reload();
            });
        };
        (function() {
            var e = document.createElement('script'); e.async = true;
            e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js';
            document.getElementById('fb-root').appendChild(e);
        }());
    </script>
    <!-- FACEBOOK JAVASCRIPT HANDLER END -->
    
    0 讨论(0)
提交回复
热议问题