Can Poyrazoğlu
Can Poyrazoğlu

Reputation: 34780

How to filter user's news feed to posts/actions from a specific app in Graph API

I have a Facebook app and I want to filter user's news feed to get latest posts/actions that was posted using my app, in Graph API.

I've found this: How to get activity from my app with Facebook Graph API? This one is okay for getting actions/posts by a specific friend (or the user itself), what I need is almost the same, with the difference that I need this "stream" by all friends of the user that use my app, not a single user.

Then I've found this: Facebook graph api : how to filter app feeds. For this one, the example in the question itself returns empty data for me (with the appropriate access token with read_stream permission). The only answer suggests to use FQL. I've tried SELECT post_id, message, comments, likes FROM stream WHERE app_id = MY_APP_ID and I got this error:

{
  "error": {
    "message": "Your statement is not indexable. The WHERE clause must contain an 
        indexable column. Such columns are marked with * in the tables linked from
        http://developers.facebook.com/docs/reference/fql ", 
    "type": "NoIndexFunctionException", 
    "code": 604
  }
}

How do I retrieve the list of all the last (say 100) posts from a specific app by the user and their friends, from the user's scope?

Upvotes: 0

Views: 2638

Answers (1)

C3roe
C3roe

Reputation: 96151

With all FQL queries, your WHERE clause must include at least one indexable field (those are marked with a star next to the field name in the docs) – for performance reasons.

So for the stream table you have a choice between source_id (id of the user whose wall the post is on) or filter_key. You can read the valid filter keys from the stream_filter table – but every user has the filter key nf for what shows up in their news feed. (post_id is also indexable, but of no use for us here.)

So you could try filtering with WHERE filter_key = 'nf' AND app_id = 'YOUR_APP_ID' – that should give you the posts that your active user is able to see in their feed that where made via your app.

You could also try with source_id, filtering that to either being equal to me() (your current user in FQL), or it being in the list of your friends (whose ids you can get from the friend table, again using me(), as a sub-query) - so like this,

… WHERE (source_id = me() OR source_id IN (SELECT uid1 FROM friend WHERE uid2 = me())) AND app_id = 'YOUR_APP_ID'

– but I think that will have less good performance, so I’d try with filter key first and see if that gets you the posts you want.


EDIT: So, as the questioner found out, using /me/home?filter=app_MY_APP_ID works apparently better, and is also easier. Whoever else might need this, they should use this version, since it is more reliable – FQL often gives less results then one would expect.

Upvotes: 2

Related Questions