FQL stream doesn't return the number of posts

2019-02-27 15:22发布

问题:

I tried "SELECT post_id, actor_id, target_id, message, likes FROM stream WHERE source_id = me() LIMIT 100", which returns me 81 instead of 100 posts, then I tried "SELECT post_id, actor_id, target_id, message, likes FROM stream WHERE source_id = me() LIMIT 50", and expecting it returns 50 posts since the first query returns 81, but the result only contains 43 post.

Wondering how LIMIT work.

Besides, the created_time doesn't really works for me, "SELECT post_id, actor_id, target_id, message, likes FROM stream WHERE source_id = me() AND created_time > 1262196000 LIMIT 100" returns 81 posts, while "SELECT post_id, actor_id, target_id, message, likes FROM stream WHERE source_id = me() AND created_time > 1262196000" returns only 5. Any idea?

回答1:

Yes, that is normal. Facebook executes your FQL and returns all posts that match your query. In this case, with 100 posts.

Then Facebook filters out the posts that are not visible to your app. This is based on the actor's privacy settings. There is no visible_to_me field in the stream table that would allow you to pre-filter your results.

If you want 100 posts, ask for 200, then display the first 100. Most of the time, you'll get at least 100 posts in the result.

If you query stream without a LIMIT, you will get up to the last 50 posts or the last 30 days worth of items, whichever is fewer.

As a bonus, for your created_time queries, you can use strtotime() to create timestamps in FQL if you don't think in UNIX time stamps (I don't). It parses the same strings as the PHP strtotime() function.