-
Rafael Pellon
-
Anonymous
-
Rafael Pellon
-
Anonymous
-
Anonymous
-
Anonymous
-
Khenidm
-
Anonymous
-
http://bobbelderbos.com/ Bob Belderbos
-
FrostyTop
-
http://bobbelderbos.com/ Bob Belderbos
-
http://bobbelderbos.com/ Bob Belderbos
my facebook
my skype




FQL: a powerful way to query Facebook’s Graph API
Today a post on FQL (Facebook Query Language). I will give you some examples that hopefully show the power of this SQL-like querying interface of the Facebook API.
So in short: FQL lets you query Facebook’s Graph API (what is the Graph API?).
Some use cases:
1. get all comments for a specific URL
For example to see the comments on this book that was added to My Reading List: http://www.bobbelderbos.com/books/?googleID=UgrUeIwsS60C
Query:
This returns:
[ {"post_fbid": "10150238413182479", "fromid": 628517118, "object_id": 10150208342007479, "text": "worth every penny, one of the best css titles I have read.", "time": 1310773947 } ](more info on comments and replies per comment)
2. get all members of my BobsBlog Facebook Group
Query:
3. get all the music your friends like – I used this one in friendsjukebox.com
(requires extended permission: friends_likes)
Query:
!! Note the batching of multiple queries into a single call !!
Snippet output:
… you can do the same for movies – query:
4. get all birthdays of my friends of this month
(requires extended permission: friends_birthday)
Query:
!! Note the use of substr in this query !!
Other functions that are available are now(), strlen(), substr() and strpos().
Fetch URL to execute the query
XML and JSON are supported formats. I am using JSON for this example.
$oauth_token is obtained by the Facebook’s Authentication: you need to create a Facebook App first and get the user to login and grant permission to your app (I will do a followup post …)
$query = "https://api.facebook.com/method/fql.query?query="; $query .= urlencode("<above query>"); $query .= "&access_token=".$oauth_token."&format=json"; $out = file_get_contents($query); $response = json_decode($out, true); echo '<pre>';print_r($response);echo '</pre>';FQL Test Console
There is a great test console where you can play with the queries. With another user account FQL console gave me “Something went wrong. We’re working on getting it fixed as soon as we can.” It seems you need to have an Application setup and the test user might need to have granted the extra permissions him/herself.
A handy trick is to click on the URL in the FQL console, it will open a new tab with the URL to fetch. For example 1 that would be:
FQL Tables
Of course a lot more is possible, see all Tables. The only limitation is that you can only query indexable properties (columns)
What’s next?
In the next post I will iterate over example 4. (birthday calendar) to show you how to use FQL as a workhorse for the input of your Facebook app. I will also cover some more aspects of the Facebook API like authorization and dialogs …
From here on …
You can subscribe to this blog, join my Facebook group, comment on this post below, or find me on twitter @bbelderbos.
By the way, if you have interesting topics you would like to see covers, just drop me a message, I am open to anything web-related.
You might also like:
Enjoyed this article?