The hello-world basics as of 9/20/12
Of the two ways to query, which is better? The answer is complicated... In the end, the Facebook Graph API is my preferred. It is simpler, the returned data is better formatted and its newer version. FQL can do more, but not much more since the addition Field Expansions, which were just added the end of last month!
The Graph API query to get the feed is dead simple: graph.facebook.com/me/home
- The above /me/home query takes ~ 2.5 seconds, try it
I overlooked this at first because the facebook developer docs describe it as "an outdated view, that does not reflect the News Feed on facebook.com"... Turns out it's good enough!
To contrast the elegance of the above Graph API query, to get a similar feed with comparable data from FQL you have to resort to shit like:
{
"query1": "SELECT post_id, type, actor_id, created_time, message, description, description_tags, privacy, likes, comments, action_links, attachment FROM stream WHERE filter_key in (SELECT filter_key FROM stream_filter WHERE uid=me() ) AND type = 80 AND is_hidden = 0 LIMIT 10",
"query2": "SELECT id, name, url, pic FROM profile WHERE id IN (SELECT actor_id FROM #query1)"
}
- The above FQL query takes ~ 8 seconds, try it
I also experimented with trying to construct a similar feed from scracth. For example, the Graph API query below gets 60 posts, 20 each from your friends, those you are subscribed to and the pages you have liked:
me?fields=likes.limit(10).fields(posts.limit(2)), subscribedto.limit(10).fields(posts.limit(2)), friends.limit(10).fields(posts.limit(2))
- ~ 6 seconds, try it
The Facebook Developer docs say that the Graph API home-feed query returns an "array of Post objects containing (up to) the last 25 posts" ... It should mention that it returns up to 25 posts PER REQUEST, in otherwords it's paginated and you can load 25 posts, then 25 more, then 25 more, etc. ... =)
I hope Facebook sticks to the Developer Map...