简体   繁体   中英

Facebook Graph API: get all the friends' likes

I don't particularly fancy the idea of getting a list of friends with 'me/friends' and then iterating over the list to get likes for a particular friend with '%id%/likes' - this takes way to long.

Is there a way to bulk query likes of users' friends in a single API call?

Thanks.

You can use FQL multi-query to get all at once, here is how:

{
"friends":"SELECT name, uid FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1 = me())",
"friendsLikes":"SELECT uid, page_id FROM page_fan WHERE uid IN (SELECT uid FROM #friends)",
"pages":"SELECT page_id, name FROM page WHERE page_id IN (SELECT page_id FROM #friendsLikes)"
}

You can test this in http://developers.facebook.com/tools/explorer/
You are going to get three result sets one after another, list of friends, list of all of their likes together and then list of page names.
(Note that the query may take a while to execute, so you may want to put a LIMIT on the first line. After uid1 = me() put a LIMIT 5 for example, for testing...)

Then include it in your code in whatever language/platform you are using, for example on iOS: http://developers.facebook.com/docs/howtos/run-fql-queries-ios-sdk/

You can also do the same query using the Graph API:

https://graph.facebook.com/me/friends?fields=name,id,likes.limit(100).fields(id,name)&limit=100

This will solve the issue of the grouping.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM