Search code examples
facebook-graph-apifacebook-fqlfql.multiquery

How to get all friends from a user that likes a give page?


How can i get all my friends that likes a given page without itearting over the list of friends and the list of likes for that friend?

The dumbway would be like:

friends_like_page = []
for f in friends:
   for l in friends.like:
      if l = page_id:
        friends_like_page.append(f)

But i'm wondering if there's a way to construct a FQL query for this.

Advance #2 and SOLVED:

Using the advice by @Igy i could solve it. I posted the answer below there. Anyway, i'm accepting Igy's answer becouse it was his idea that helped me.

Advance #1:

Ok, i've got this right now:

Fetch all friends:

SELECT uid2 FROM friend WHERE uid1 = me()

Fetch page fan from a user UID:

SELECT uid, page_id FROM page_fan where uid = UID

Combined:

SELECT uid, page_id FROM page_fan WHERE uid in (SELECT uid2 FROM friend WHERE uid1 = me())

But, it doesn't seem to work properly. What's going on?


Solution

  • You can't get a list of who likes a page, you always need to start with the users and work back towards the page - the quickest way to do this is probably to retrieve the users' friends' likes in a batch query and compare the results with some array search operators