How to display recent comments from Facebook Comments social plugin?

前端 未结 2 930
甜味超标
甜味超标 2021-01-05 16:49

Well, I just have a pretty straight question: How do I display recent comments from Facebook Comments social plugin on my website?

I have integrated the facebook com

2条回答
  •  再見小時候
    2021-01-05 17:21

    The social plugin has some ways to change its layout, but all of them will allow the user to write a new comment. One way to get only the comments is by FQL.

    To use it, include the facebook all.js on your code (I guess you have it, once you're using the social plugin) and do the following:

    First create a div with class 'comments':

    Then, do the following in javascript

    FB.api(
        {
        method: 'fql.query',
        query: 'select text from comment where object_id in (select comments_fbid from link_stat where url ="http://developers.facebook.com/docs/reference/fql/comment/")'
        },
        function(response) {
    
            $.each(response, function(i, e) {
                $(".comments").append("
    "+e.text+"
    "); }); } );

    If your div has a class that is not comments, just replace $(".comments") with $(".your-class"). This code will create several elements with class comment inside your comments element.

    I'm using jQuery to iterate the comments.

    Hope it helps!

提交回复
热议问题