Facebook Event.subscribe comments.create не работает - PullRequest
1 голос
/ 27 февраля 2011

Может кто-нибудь сказать мне, почему это не работает для меня?

Пример страницы здесь

http://totalcommunitycollegemove.com/post-438.html

window.fbAsyncInit = function() {   
    FB.init({appId: '194189377275548', status: true, cookie: true,
         xfbml: true});

};
(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);
}());

function catchCommentAdd()
{
    $.ajax({
        type: "POST",
        url: "ajaxCommentCount.php",
        data: "id=<?php echo $_GET['id']; ?>&direction=up",
        dataType: "json"
    });
    return true;
}

function catchCommentDelete()
{     
    $.ajax({
        type: "POST",
        url: "ajaxCommentCount.php",
        data: "id=<?php echo $_GET['id']; ?>&direction=down",
        dataType: "json"
    });

    return true;
}

FB.Event.subscribe('comments.create', function(response) { 
    alert(response);
    catchCommentAdd();
});

Ответы [ 4 ]

4 голосов
/ 02 марта 2011

У меня была такая же проблема, но, возможно, нашел решение (работает на моем тестовом сайте). Кажется, что название события "comments.create" неверно. Правильным (или, по крайней мере, рабочим) событием является "comment.create" (без s)

Вот мой фрагмент кода:

<script>
    window.fbAsyncInit = function() {
        FB.init({
            appId:  'APP_ID',
            status: true,
            cookie: true,
            xfbml:  true
        });

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

    };
    (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>
<fb:comments href="YOUR_URL" num_posts="5" width="500" ></fb:comments>
2 голосов
/ 10 марта 2011

Используйте «comment.create», а не «comments.create», это единственное число.

0 голосов
/ 08 марта 2011

Вы читаете документацию Facebook?Это большая ошибка, к сожалению.Попробуйте использовать comments.add вместо comments.create ...

0 голосов
/ 27 февраля 2011

Этот код:

FB.Event.subscribe('comments.create',
function(response) { 
    alert(response);
    catchCommentAdd(); });

Полагается на то, что Javascript SDK Facebook уже загружен. Поскольку это происходит асинхронно, вы должны поместить код в функцию window.fbAsyncInit после вызова FB.init:

window.fbAsyncInit = function() {   
    FB.init({appId: '194189377275548', status: true, cookie: true,
         xfbml: true});

    FB.Event.subscribe('comments.create', function(response) { 
        alert(response);
        catchCommentAdd();
     });
};
...