Facebook graph api comment count

假装没事ソ 提交于 2019-12-02 19:13:15

I was having same problem, just adding likes.summary(true),comments.summary(true) in parameter in against "fields" worked for me.

e.g. I used https://graph.facebook.com/me/feed?access_token=ACCESS_TOKEN&fields=story,from,story_tags,likes.summary(true),comments.summary(true)

instead of https://graph.facebook.com/me/feed?access_token=ACCESS_TOKEN

Also you can add other parameters if you want; separated by a ,

summary=true is what you are looking for

Get likes count :

114916098537132_1265715836790480/likes?summary=true

Get comments count

114916098537132_1265715836790480/comments?summary=true

Get shares count :

114916098537132_1265715836790480?fields=shares

And last [ combining all 3 ]

114916098537132_1265715836790480?fields=shares,likes.summary(true),comments.summary(true)

Improved version ( add limit(0) to removes list of likes and get only summary ):

114916098537132_1265715836790480?fields=shares,likes.limit(0).summary(true),comments.limit(0).summary(true)
Cormac Driver

You can get total comment count via FQL. See this question below as reference:

Facebook API - comment count via FQL

Here's the query you need: SELECT comment_info FROM stream WHERE post_id = ...

This works perfectly with me:

fields=shares,created_time,comments.summary(true).limit(0)

This return comments count at summary and return 0 comments at the same time which is perfect as you only need the comment count.

If you'd like to count everything on Facebook. (That number is visible for Facebook's User)

You should use FQL (Facebook Query Language) instead of Graph API.

Facebook Query Language Reference

This situation you should to query

SELECT comment_info FROM stream WHERE post_id = ...
Balla Győző

You can do such requests:

{pageid}/posts?fields=comments.summary(1){id}

It will return a list of posts including comments count of each post. Here I have returned only the comment id because I only need the number of comments per post, but of course you can include many other fields:

{pageid}/posts?fields=comments.summary(1){id,message},id

Or to make less changes to you excisting code, use:

    $.each(json.data,function(i,fb){
    ...
       var commentsCount = 0
       if(fb.comments!=undefined){
          commentsCount=fb.comments.data.length
       }
    ...
    }

commentsCount holds number of comments for active child

Karm

Try the following:

{
    "data": [
        {
            "id": "447235535389660_1226199",
            "from": {
                "name": "Harjeet Walia",
                "id": "100004980601083"
            },
            "message": "Price",
            "can_remove": false,
            "created_time": "2013-09-06T10:39:01+0000",
            "like_count": 0,
            "user_likes": false
        },
        {
            "id": "447235535389660_1226152",
            "from": {
                "name": "Shoba Dhyani Jakhmola",
                "id": "100000906896060"
            },
            "message": "baap re kitna mehnga !",
            "can_remove": false,
            "created_time": "2013-09-06T10:05:09+0000",
            "like_count": 0,
            "user_likes": false
        }
    ],
    "paging": {
        "cursors": {
            "after": "MQ==",
            "before": "NA=="
        }
    }
}

then

int commentCount = <JsonNode Var with above data>.path("comments").path("data").size();

Here commentCount will give the number of comments.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!