Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
502 views
in Technique[技术] by (71.8m points)

javascript - How to list all comments in my domain

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...