简体   繁体   中英

Get posts made by Facebook friends only on page through GraphAPI

tl;dr: Is there a certain way to retrieve the posts made to a page, but only those made by the authenticated user's friends?

I am working on an iOS app and I can retrieve ALL the posts made to a page using the GraphAPI method [facebook requestWithGraphPath:@"pageID/feed" andDelegate:self]; and can also retrieve the friends list of the currently authenticated user using [facebook requestWithGraphPath:@"me/friends" andDelegate:self];

Is there a way to filter the first data set to get those submitted only by ids in the second data set server side (ie: through GraphAPI) or is my best option client side (my code) filtering of the results?

You can use FQL to accomplish this with a pretty simple query:

SELECT post_id FROM stream WHERE source_id = PAGEID AND actor_id IN (SELECT uid2 FROM friend WHERE uid1 = me())

The second part of this query in parenthesis is selecting a list of user IDs of the current users friends (determined by the access token used to query) and then this UID list is being used to filter the first part of the query which selects a list of post_ids which are posted to a particular page ID (make sure to substitute the placeholder for your own Page ID).

This will give you just a list of Post IDs, however the stream table documentation will show you more of the fields that you can select.

Note that FQL might be considered a separate API from the Graph API, however it can actually very simply be run through the Graph API, as shown in this blog post .

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