Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to display recent comments from Facebook Comments social plugin?

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 comments social plugin on my wordpress blog and I just want to put a widget on my sidebar that displays the recent comments from the social plugin.

Thanks!

like image 334
Raven Avatar asked Jun 26 '11 12:06

Raven


People also ask

How do you see recent comments on Facebook posts?

Tap in the top right of Facebook, then tap your name. Tap below your profile picture, then tap Activity Log. Tap Filter at the top of your activity log to review activities like: Things you've posted.

How do I view Facebook comments on my website?

Click the “Add New Widget” button. Click on the “Facebook Comments” box. Name your widget by filling in the “Widget Name” field. Choose whether you would like customers to comment on the “Current Website Page” that they are on or a “Custom URL”.

How do I change Comment settings on Facebook?

Visit your Facebook profile or page. Click the dropdown button at the top-right corner and go to Settings & privacy > Settings. Under Settings, go to “Public Posts” in the sidebar on the left. Scroll down the page and click the 'Edit' button next to “Comment Ranking”.


1 Answers

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':

<div class="comments"></div>

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("<div class='comment'>"+e.text+"</div>");
        });         

    }
);

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!

like image 61
Raphael Petegrosso Avatar answered Sep 21 '22 18:09

Raphael Petegrosso