facebookfacebook-graph-apifacebook-php-sdkfacebook-graph-api-v2.2

How do i get photos of user with like / comment count, graph api v2.2


In my application i am getting photos of user from Facebook using graph api request. For this i am making this request:

 //Graph API request

 me?fields=photos{album{id},id,from{id},name,created_time,place{id},comments{comment_count},likes,tags{id}}

This gives me all photos with comments / likes of photos but not the comment/like count. The like/comment data is array with paging so count cannot be determined by array length. For getting like/comment count i need to make another batch request for each photo object id.

 {photo-object-id}/likes?summary=true

Using FQL it was possible in single request, Is there any way to get desired result from single request using graph api v2.2.

Thanks.


Solution

  • Try this query:

    /me?fields=photos{album{id},id,from{id},name,created_time,place{id},
      comments.summary(1),likes.summary(1),tags{id}}
    

    summary needs to be set to 1 in order to retrieve the summary -> total_count data.

    If your were requesting the comments via the comments edge, then the syntax would be /{object-id}/comments?summary=1 – but for the field expansion syntax you are using, comments.summary(1) must be used to indicate that you want the summary for the comments (and same for the likes)