I use the code below to catch a new facebook comment on my blog, and make some actions (push data into a db and thank user):
<script type='text/javascript' src='//connect.facebook.net/en_US/all.js'></script>
<script type="text/javascript">
FB.Event.subscribe('comment.create', function(a) {
FB.api('comments', {'ids': a.href}, function(res) {
var ufb_message = '';
var ufb_from = '';
var ufb_name = '';
var ufb_jump = false;
var testJSON = res[a.href].comments.data;
var i=0;
while(i < testJSON.length) {
try{
var tempJSON = testJSON[i].comments.data.pop();
if (testJSON[i].comments.count > 0 && tempJSON.id == a.commentID) {
ufb_message = tempJSON.message;
ufb_from = tempJSON.from['id'];
ufb_name = tempJSON.from['name'];
ufb_time = tempJSON.created_time;
i=testJSON.length;
ufb_jump = true;
}
} catch(e) {}
i++;
}
if(!ufb_jump) {
var data = res[a.href].comments.data.pop();
ufb_message = data.message;
ufb_from = data.from.id;
ufb_name = data.from.name;
}
alert('Thanks for your comment!' + ufb_name);
<?php
[...] php code to execute [...]
?>
});
});
</script>
If comments are < 25 all is ok. From the 26th comment data returned are always about the 25th comment.
I suppose it's because of the default limit=25 in json
p.e.: https://graph.facebook.com/comments/?ids=http://www.isocial.it/aggiornamento-ios-7-beta-iphone
returns the first page with 25 comments.
when I have more comments, data catch from my code always refer to the 25th comment.
many thanks for your help.
At the end of your data, there should be a "paging" paramater, this will return more of your comments. See https://developers.facebook.com/docs/reference/api/pagination/