login button not displaying everytime

I recently upgraded to open graph and implemented some of the facebook social plugins on my website like fb:friendpile fb:like-box etc

Ever since I implemented these new features, I'm seeing some random behavior with these plugins.

Like on my home page, when you type in the URL and go for the first time, none of the facebook social plugins are rendered - no login button, no friendpile no like - nothing.

But when you hit CTRL F5 - they appear. First I thought it probably has somethin to do with my machine but yesterday two of my users reported the same issue.

I googled around and it seems to have something to do with where you place your connect code. Right now, I have this relevant portion of the script placed in my head tag - I even tried placing it right before the end of body tag - but it made no difference.

<script type="text/javascript">
    window.fbAsyncInit = function() {
       FB.init({appId: '<?php echo Zend_Registry::getInstance()->configuration->facebook->appid;?>', status: true, cookie: true, xfbml: true});

                /* All the events registered */
                FB.Event.subscribe('auth.login', function(response) {
                    // do something with response
                    login();
                });
                FB.Event.subscribe('auth.logout', function(response) {
                    // do something with response
                    logout();
                });
            };
            (function() {
                var e = document.createElement('script');
                e.type = 'text/javascript';
                e.src = document.location.protocol +
                    '//connect.facebook.net/en_US/all.js';
                e.async = true;
                document.getElementById('fb-root').appendChild(e);
            }());

            function login(){        
                document.location.href = "<?php echo $this->baseUrl(); ?>/login/log";
            }
            function logout(){
                FB.init({appId: '<?php echo Zend_Registry::getInstance()->configuration->facebook->appid;?>'});               
                FB.logout(function(response) {
                      // user is now logged out
                    }); 
                document.location.href = "<?php echo $this->baseUrl(); ?>/login/logout";
                return false;
            }
</script>

Any insights in trouble shooting this will be appreciated Thanks


Your logout logic seems problematic (you call FB.logout() in logout() -- but also call logout() on the 'auth.logout' event, which seems circular). You should also remove the FB.init() call inside your logout() function. The lack of xmlns:fb on the <html> tag is often the cause of XFBML not rendering in IE, so I'd double check that. You could also try replacing the async loading with sync loading using a normal script tag like:

<script src="http://connect.facebook.net/en_US/all.js"></script>

But a live repro case would be more helpful since your code looks fine for the most part.

EDIT: You can also checkout http://fbrell.com/xfbml/fb:login-button for examples.

链接地址: http://www.djcxy.com/p/35806.html

上一篇: Facebook“Like Button”显示计数格式不正确

下一篇: 登录按钮不会每次显示