开发者

Get Facebook comments via Graph API, but not hidden comments from the social plugin Facebook comments box

I already use the Graph API t开发者_高级运维o get Facebook comments from a URL. That's working nice.

But I have a problem. Comments that are hidden from the box (social plugin), and are displayed in the JSON response of the API. But I don't want those to appear in. And there is no field to get information if it's a moderated comment or not.

Array(
    [id] => 10150178257599373_16650724
    [from] => Array
    (
        [name] => Books, EBooks
        [category] => Author
        [id] => 182404265135935
    )
    [message] => Thank you, Facebook
    [created_time] => 2011-06-06T03:21:06+0000
)

As you can see, there is no field with the information "moderate". What do I do?


Double moderate!

You could create a database entry for every new comment via the Fb.Event.subscribe and as soon as you moderated the comment on Facebook, mark the comment in your database and only print out the marked comments. It's a bit annoying, but so far propably the only solution :(

It would be great if Facebook could implement that information in their JSON, or better only put moderated comments in the Graph API.


I ran into this recently and was able to use FQL to get the comments without those which are marked private (which I assume means unmoderated?) I did this in javascript, but there is no reason this code couldn't be rewritten in php or whatever.

 fql = "SELECT post_fbid, fromid, object_id, text, time, comments FROM comment WHERE object_id IN (SELECT comments_fbid FROM link_stat WHERE url ='" + commentsUrl + "') and is_private = 0 limit 10";

After getting back this data, loop through and grab all the user ids:

FB.api({method: 'fql.query',query: fql},function (comments) {
    $.each(comments, function (index, comment) {
       userIds.push(comment.fromid);
    });
});

With the user ids, use the graph api to get each users name and create an object that resembles the json response of the graph api:

FB.api('?ids=' + userIds.join(','), function (responseIds) { 

    $.each(comments, function (index, comment) {
        comment.message = comment.text;
        comment.created_time = comment.time;
        comment.from = {id: comment.fromid, name: responseIds[comment.fromid].name};

    });
});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜