0

I have to convert some FQL into Graph2.1 http requests.

The fql

select post_id, likes from stream where source_id = {page_username} and filter_key='owner' limit 1000

This returns the post ids and the likes to that post for any page I can enter for the {page_username}. The likes is an array that contains a "count" key value pair.

The issue is when I use the new 2.1 I can't get a total count of likes for the post.

GET /v2.1/{page_username}?fields=posts{id,likes} HTTP/1.1
Host: graph.facebook.com

I can only get an array of users that have liked the post. The issue is it's paginated also so it's not a complete list.

The refrence says there's a "total_count" field. Facebook Graph Reference

GET /v2.1/{page_username}?fields=posts{id,likes{total_count}} HTTP/1.1
Host: graph.facebook.com

But this returns an error

"error": { "message": "(#100) Unknown fields: total_count.", "type": "OAuthException", "code": 100 }

Any ideas on how I can get just a like count for a post?

Frank D
  • 612
  • 4
  • 14
  • Any progress in your research? I have the same problem. – angelcervera Sep 21 '14 at 21:30
  • Not really. It seems FB is wanted to limit the work load on their side. I am working in C# so I am now just taking all the data, using LINQ to JSON to query and count the likes. Kind of a pain considering it was so easy with FQL. – Frank D Sep 22 '14 at 14:05
  • Just posted and answer. Hope it helps – Frank D Oct 20 '14 at 16:31

1 Answers1

4

So I found the easy way to get the answer.

GET /v2.1/{page_username}?fields=posts{id,likes.summary(true).filter(stream)} HTTP/1.1
Host: graph.facebook.com

By adding the ".summary(true)" and ".filter(stream)" after "likes" I now get the following JSON

{...
    "likes": {
        "data": [ .... ]
        "paging": { .... }
        "summary": {
            "total_count": 12345 
        }
    }
}

This also working for comments

{page_username}?fields=posts{id,comments.summary(true).filter(stream)}

Getting the same structure with the summary and total count.

".summary(true)" will get the summary key in the JSON.

".filter(stream)" will ensure that you get ALL the comments/likes counted. If this is missing it will not count the nodes that Facebook as decided to "hide" due to their low "Top Story" value.

In the API reference these modifiers are only listed on the "/{object-id}/comments" section but works well for both likes and comments.

Reference: https://developers.facebook.com/docs/graph-api/reference/v2.1/object/comments

Frank D
  • 612
  • 4
  • 14