Jun
19

Facebook FQL Query Basics.

Tags:  Facebook FQL 

Facebook FQL
If you have integrated Facebook Connect already, you probably want to do more than just log in. This tutorial will show you how to query some user information from Facebook after the user has been authenticated. We can use Facebook adaptation of SQL intuitively named FQL (or FSQL) to do this. I will go over basic setup/syntax and outputting the information.

Note: as always, I am assuming you already have Facebook Connect setup. If you are looking for a tutorial for basic setup and implementation, please read this article first.

First, create a new Facebook object with the API key and API secret from the application setup through Facebook.

1. Create a new Facebook object.
$facebook = new Facebook('$apiKey', '$apiSecret');


Next, we will need to get the Facebook login id through the created Facebook object.

2. Retrieve the current logged in users Facebook id.
$fb_user = $facebook->require_login();


Now you are ready to run queries on the Facebook user that is logged in. Here is how to get the users name and picture. If you want to know which tables and columns their are to be queried, please look here.

3. Run a FQL query and retrieve some simple data.
$query = "SELECT name, pic FROM user WHERE uid = '$fb_user'";
$result = $facebook->api_client->fql_query($query);

//rename all the useful information.
$user_name = $result[0]["name"];
$user_pic_id = $result[0]["pic"];


And that's all their is to it! Let me know if you have any questions about building queries.

Comments

Nice post....got basic idea..Thanks a lot

vinod 4 months ago

Leave a Comment

Name
Email (optional)
Website (optional)
...or login using Facebook to bypass these fields.
Messageusable tags: <b> <i>
Robot?
Loading tweets...
Site designed, developed and coded by Marc Whitbread and Whitbread Design ©2010