Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 ?

like image 882
Scharron Avatar asked Feb 09 '12 15:02

Scharron


3 Answers

This probably isn't exactly what you're looking for, but given the fact that facebook (AFAIK) doesn't provide (and will probably never provide) the ability to do this. I think you should simply store the information yourself and then query the data from your own database. It would be like what you're doing in your question, but you can optimize it since it's your database.

I'm sure you thought about this already, but someone had to say it.

like image 121
derickito Avatar answered Oct 19 '22 03:10

derickito


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.

like image 25
nils Avatar answered Oct 19 '22 03:10

nils


If the answer derickito gave is not enough, you should explore getting your app on the Facebook white-list (aka become a partner) to get at some the private Graph API where this functionality might exist, but is not available for "normal" application that are stuck using the public Graph API.

like image 3
DMCS Avatar answered Oct 19 '22 04:10

DMCS