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

3

22

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 ?

Campestral answered 9/2, 2012 at 15:51 Comment(2)
Try using the Facebook Activity plugin w/ custom open graph actions as I describe hereBelletrist
Has the situation changed or do we still have to use batched requests?Libava
P
3

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.

Pyrethrum answered 3/9, 2012 at 13:36 Comment(2)
Just a few days to late to claim my bounty - sorry for you but thanks so much for letting us know.Libava
Just goes to show how volatile the FB API can be. Hopefully this won't be yanked or modified in the future.Ultra
U
6

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.

Ultra answered 13/2, 2012 at 21:22 Comment(2)
I really want to only use facebook API. I'm currently duplicating data, and want to migrate to a full-facebook-api solution.Campestral
Like I said in my answer "this probably isn't exactly what you're looking for", but if you're looking for a full-facebook api solution then you are limited to what facebook will let you do. There is no way around this no matter how much you wish for it. FQL doesn't let you do it, the API doesn't let you do it. Either you become dependent on facebook and do only what they let you do or you duplicate data and do whatever you want to do. It's that simple, there is not hidden solution. Again, probably not what you want to hear.Ultra
G
3

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.

Globin answered 15/2, 2012 at 16:5 Comment(0)
P
3

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.

Pyrethrum answered 3/9, 2012 at 13:36 Comment(2)
Just a few days to late to claim my bounty - sorry for you but thanks so much for letting us know.Libava
Just goes to show how volatile the FB API can be. Hopefully this won't be yanked or modified in the future.Ultra

© 2022 - 2024 — McMap. All rights reserved.