Search code examples
apifacebook-graph-apifacebook-opengraphfacebook-social-pluginsopen-graph-beta

Retrieve the list of friends that did a custom action on a custom object in open graph 2


I would like to do something like facepile using the graph api with open graph 2 actions : from a custom object and a custom object, give me the friends (using my facebook application) that did this action on this object.

The problem is that using FQL, I cannot query custom objects and actions. Using the graph API, I cannot find a way to intersect the list of my friends with the object I'm interested in.

The best I could do was the following using the batch mode of the graph API :

batch=[
  // First we get the list of friends that are using my facebook application
  { "method": "GET", "relative_url": "fql?q=SELECT+uid+FROM+user+WHERE+uid+IN+(SELECT+uid1+FROM+friend+WHERE+uid2=me())+AND+is_app_user=1+LIMIT+0,49", "name": "friends"},
  // Then query each friend to get the list of objects that went through my namespace:testaction
  { "method": "GET", "relative_url": "{result=friends:$.data.0.uid}/namespace:testaction" },
  { "method": "GET", "relative_url": "{result=friends:$.data.1.uid}/namespace:testaction" },
  ...
  { "method": "GET", "relative_url": "{result=friends:$.data.49.uid}/namespace:testaction" }
]

It's quite inefficient and does not fully resolve my issue since :

  • I still have to filter the results to get only the one that matches the object I want
  • If there is a large number of objects in namespace:testaction, I have to go through paging, doing more queries (I try to minimize the number of queries)

Do you see a better way to do this ?


Solution

  • It's now possible to do this with one Graph API request:

    GET https://graph.facebook.com/me/friends?limit=50&fields=name,namespace:testaction.limit(100)
    

    see field expansion and updates to the graph API.