Skip to content

Instantly share code, notes, and snippets.

@d4tocchini
Created September 20, 2012 09:08
Show Gist options
  • Save d4tocchini/3754819 to your computer and use it in GitHub Desktop.
Save d4tocchini/3754819 to your computer and use it in GitHub Desktop.

Facbeook Graph API, what you need to know

The hello-world basics as of 9/20/12

Which is better, FQL or the Facebook Graph API?

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!

What is the query for the Facebook Home Feed ?

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))

Isn't the Facebook Home Feed limited to just 25 posts?

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. ... =)

What if Facebook changes shit on us?

I hope Facebook sticks to the Developer Map...

Facbeook Graph API, what you need to know

The hello-world basics as of 9/20/12

Which is better, FQL or the Facebook Graph API?

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!

What is the query for the Facebook Home Feed ?

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

Isn't the Facebook Home Feed limited to just 25 posts?

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. ...

What if Facebook changes shit on us?

I hope Facebook sticks to the Developer Map...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment