Facebook Comments Plugin:comment.create和comment.remove对登录用户不起作用

时间:2011-11-12 00:28:48

标签: facebook facebook-comments

当用户尚未登录Facebook或页面已有评论时,代码正确执行;但是当用户已经登录并且正在添加第一条评论时,comment.create和comment.remove通常不会触发:

<div id="fb-root"></div>
<script type="text/javascript">
<!--
window.fbAsyncInit = function() {
FB.init({appId: 'FACBOOKAPPID', oauth: true, status: true, cookie: true, xfbml: true});

FB.Event.subscribe('comment.create', function(response) {
    alert(response.commentID);         
});
FB.Event.subscribe('comment.remove', function(response) {
    alert(response.commentID);
}); 
};

(function() {
var e = document.createElement('script');
e.type = 'text/javascript';
e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js#xfbml=1';
e.async = true;
document.getElementById('fb-root').appendChild(e);
}());
//-->
</script> 

<fb:comments href="URL" num_posts="1" width="500"></fb:comments>

建议?

1 个答案:

答案 0 :(得分:0)

<script>
//INCLUDE THE SCRIPT FIRST
(function(d, s, id) {
  var js, fjs = d.getElementsByTagName(s)[0];
  if (d.getElementById(id)) return;
  js = d.createElement(s); js.id = id;
  js.src = "//connect.facebook.net/it_IT/all.js#xfbml=1&appId=APP ID";
  fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));


//INITIALIZE THE OBJECTS
window.fbAsyncInit = function() {
    FB.init({
        appId:  'APP ID',
        status: true,
        cookie: true,
        xfbml:  true,
        oauth: true
    });

    //AND THOSE WILL FIRE THE EVENTS :)

    FB.Event.subscribe('comment.create',
        function (response) {
            console.log('create', response);
        });
    FB.Event.subscribe('comment.remove',
        function (response) {
           console.log('remove', response);
        });

};
</script>

<fb:comments class="fb-comments" href="URL" data-num-posts="2" data-width="630"  notify="true"  migrated="1"></fb:comments>