How to list all comments in my domain
Asked Answered
O

3

9

I am using the HTML5 version of Facebook Comment in my website. I have my own Facebook APP Id.

Using Graph-API, and FQL (I think this is how to do it), I want to list all the Comments posted in my website.

Example -

Page Title1
--Comment1
--Comment2
--Comment3

Page Title2
--Comment1
--Comment2
--Comment3

Page Title3
--Comment1
--Comment2
--Comment3

etc.

Please help me out.

Orchestra answered 18/4, 2012 at 5:11 Comment(1)
If you appreciate any of the answers below, please mark one of them as the right answer. This will increase your reputation, and the answer composer's.Crossland
C
7

It is possible, in two different ways, as long as you have a fixed set of sub-pages you want to fetch comments from.

If you have a large amount of sub-pages, or a variable amount, then you don't have a good scalable solution - and many have been looking for one:

For a Fixed set of sub-pages in your website, you can either use a batch request, or an FQL query.

Batch Request


First, you need your access token. Just enter the following as a url in a browser (credit to this website ):

https://graph.facebook.com/oauth/access_token?type=client_cred&client_id=APP_ID&client_secret=APP_SECRET

And this is the javascript jquery code to make a batch request to fetch comments from several urls at once:

$.ajax({
  url: 'https://graph.facebook.com/',
  type : "POST",
  data: {
    access_token : 'YOUR_APP_ACCESS_TOKEN',
    batch : '[ \
    {"method":"GET","relative_url":"URL1"}, \
    {"method":"GET","relative_url":"URL2"} \
    ]'
  },
  success: function(data) {
    jdata = JSON.parse(data);
    $.each(jdata, function(index,value){
        jdata[index].body = JSON.parse(value.body);
        console.log(value.body);
    });
    // Do whatever you want with jdata
  }
});

FQL


inspired from this post

FB.api({
    method: 'fql.query',
    query: 'select text from comment where object_id in (select comments_fbid from link_stat where url="URL1" or url="URL2")'
  }, function(response) {
    // Do something with results
  });

Conclusion

Because of this limitation of Facebook, I plan to switch to disqus.com, which apparently supports this feature (As you can see from this blog, for example. (search for 'recent comments')

Crossland answered 2/5, 2012 at 11:21 Comment(0)
L
1

Rather than list all the comments on your site, Facebook wants you to implement code to get notified when a new comment is posted anywhere on your site.

To make this happen, you have to put some Javascript into the page where the comment is posted to also notify yourself:

window.fbAsyncInit = function(){
    console.log("subscribing to comment create");
    FB.Event.subscribe('comment.create',function(response){
        console.log("facbeook comment created: " + JSON.stringify(response));
        var commentQuery = FB.Data.query('SELECT fromid, text FROM comment WHERE post_fbid=\'' + response.commentID + '\' AND object_id IN (SELECT comments_fbid FROM link_stat WHERE url=\'' + response.href + '\')');
        FB.Data.waitOn([commentQuery], function () {
            console.log("Facebook comment: " + JSON.stringify(commentQuery));
        }); 
    });
};

Where rather than just logging the comment to the console, you would need to implement some AJAX that would send the comment back to your site where you could store the comment in your database, or send yourself an email notifying you that the comment has been posted.

Loni answered 20/7, 2013 at 8:48 Comment(0)
H
0

Reference: Facebook Comments Plugin

Say your website is http://mywebsite.com/blog.php?id=3 and you have a facebook comments plugin on it, you can access comments this way

 https://graph.facebook.com/comments/?ids={YOUR_URL}.

{YOUR_URL} becomes http://mywebsite.com/blog.php?id=3

Example 1: (Comments plugin installed on developers facebook doc website )

website: http://developers.facebook.com/docs/reference/plugins/comments

fetch comments: https://graph.facebook.com/comments/?ids=http://developers.facebook.com/docs/reference/plugins/comments

Example 2:

website: http://techcrunch.com/2011/04/08/the-seven-most-interesting-startups-at-500-startups-demo-day/

fetch comments: https://graph.facebook.com/comments/?ids=http://techcrunch.com/2011/04/08/the-seven-most-interesting-startups-at-500-startups-demo-day/

Check this too

Sample code for pulling comments can be found on this blog post

Hemmer answered 18/4, 2012 at 7:13 Comment(3)
Actually, I tried this and I am getting this output - But I do have comments in my site !! <code> { "mysite.com": { "comments": { "data": [ ] } } }Orchestra
is the comments plugin exactly located on mysite.com, you should give the complete url. I updated my answer accordingly, please checkHemmer
Be sure to escape any special characters in the url. For instance, if your url is: 'mywebsite.com/blog.php?id=3' the way to query the comments from this page is 'graph.facebook.com/comments/?http://mywebsite.com/…'Crossland

© 2022 - 2024 — McMap. All rights reserved.