Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FQL query of photos for Facebook users with large numbers of photos

I need to get photos of an FB user sorted by likes. I ran this FQL query via Facebook JavaScript SDK to get them:

SELECT object_id, src_big, src_big_width, src_big_height, link, like_info, caption, created 
FROM photo 
WHERE owner = MANY_PICS_USER_ID ORDER BY like_info DESC LIMIT 10

The query fails for users with more than 3000 photos. Turns out there are a lot of those users. Related Facebook bug is here http://developers.facebook.com/bugs/438568326189781

As a note: removing "ORDER BY like_info" makes query work, but there is no easy way for me to get those pictures, sorted by likes

To reproduce:
Pick a FB friend with at least 3000 photos, get their user Id, and run the above query (replacing MANY_PICS_USER_ID) in API GRAPH EXPLORER.

What is the best workaround? Or, can you suggest the easiest light-weight Open Graph solution?

like image 265
Anna Vital Avatar asked Nov 03 '22 13:11

Anna Vital


1 Answers

To sort photos by likes you need the following:

  • Run the query which gives first 100 results (replace me with user id):

    http://graph.facebook.com/me/photos?fields=id,source,likes&limit=100

Which return the following data structure:

"data": [
{
  "id": "1234567890", 
  "source": "http://photo.url.in.facebook.cdn.com/", 
  "created_time": "2012-09-13T22:52:34+0000", 
  "likes": {
    "data": [
      {
        "id": "1234567890", 
        "name": "Full Name"
      }, 
      .....
    "paging": {
      "next": "https://graph.facebook.com/1234567890/likes?limit=25&offset=25"
    }
  }
},
{
  "id": "312323232323", 
  "source": "PICTURE_URL", 
  "created_time": "2012-09-12T20:54:27+0000", 
  "likes": {
    "data": [..]
  }
},
....
"paging": {
  "previous": "http://PREVIOUS_URL?fields=id,source,name,height,width,link,likes&limit=100&since=123456", 
  "next": "http://NEXT_URL?fields=id,source,name,height,width,link,likes&limit=100&until=234567"
}
  • If total number of pictures is more than 100, run all next queries, from the "next" link until the num of pics will be less then 100.

  • For every picture you need to count total number of likes. If the number of likes is more than 25, run extra query from likes.paging.next until number of likes will be < 25 and get the total quantity.

  • Sort all those pics by number of likes.

So for the user with 3000 pics it will be in total 30 calls + extra calls for each picture with more than 25 likes.

like image 69
Mark Vital Avatar answered Nov 15 '22 12:11

Mark Vital