Reputation: 1063
How can i get the photo with the most likes in a facebook album and when i get for a single album how can i count for example for last 7 created albums the picture with the most likes?
Upvotes: 0
Views: 1277
Reputation: 31489
There's no option to sort Graph API results as far as I know. So, either you count and sort the results of the Graph API request
GET /{album_id}/photos?fields=album,id,likes
yourself (see https://developers.facebook.com/docs/graph-api/reference/v2.1/album/photos#read), or if you have a Graph API v2.0 app, you can use the following FQL to retrieve the most liked photo
of an album
:
select object_id, like_info.like_count from photo where album_object_id="{album_id}" order by like_info.like_count desc limit 0, 1
where {album_id}
is your actual album_id
.
Concerning the 7 last created albums, you'd have to query first for the most recent albums, and then execute the above request for each of them (because FQL doesn't support GROUP BY
statements). You can use the Batch API to run these 7 requests in parallel (see https://developers.facebook.com/docs/graph-api/making-multiple-requests).
If you put some effort in the Batch call generation, you could even do the whole 8 requests in one, if you use the referencing feature. Have a look at https://developers.facebook.com/docs/graph-api/making-multiple-requests#operations
Upvotes: 1