Question

I have a logic problem I can't seem to solve (might be possible).

Example:

  • I am inside 100 facebook groups
  • I need the 10 lastest posts of EACH group I am in.

That's pretty much it but I can't seem to find a way to do this without making a foreach loop calling the api over and over again, if I had a couple hundred more groups it would be impossible.

PS: I'm using FQL atm but am able to use graph, I've coded this in like 3 different ways but no success. This is the farthest I could get:

SELECT actor_id,source_id FROM stream WHERE source_id IN (select gid from group_member where uid = me())

It only returns from one page, maybe there's no way to return all of this without a foreach asking for each groups 10 lastest messages.

Was it helpful?

Solution

There's no need to use FQL of batching. This can be done with a simple Graph API request IMHO:

GET /me/groups?fields=id,name,feed.fields(id,message).limit(10)

This will return 10 posts for each of your groups. In case there too much data to be returned, try setting the limit parameter for the base query as well:

GET /me/groups?fields=id,name,feed.fields(id,message).limit(10)&limit=20

Then, you'll get a next field in the result JSON. By calling the URL contained in this field, you'll get your next results. Do this until the result is empty, then you reached the end.

OTHER TIPS

You can use batch calls, described here https://developers.facebook.com/docs/graph-api/making-multiple-requests/

Using batch requests, you can request upto 50 calls in one go. Note than batch request doesn't increase the rate limits, so if you make 50 requests in batch, it will be considered as 50 calls, and not one. However you will get the response in a shorter time.

If you think you're making too many calls, you should put some delay in between calls and avoid rate limiting.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top