Blog > detail

Just my tiny mind

Facebook Query Language

26-2-2012 Admin General 2 Comments

FQL (Facebook Query Language)

FQL (Facebook Query Language) is some kind of query database used to mining data in facebook platform. You can once use this FQL after the user agree to connect to your application using facebook login(see my previous post). It is also depend on the permission you had to access the user data.


There are many tables in FQL (Facebook Query Language), but usually you may use user table just to support the facebook login. In my application I only need username and email, thus I only access the table user.


The query of FQL (Facebook Query Language) that I use here is "SELECT name,email FROM user WHERE uid = me()"; In this case the query will result the name and email of user that already approve my application. Once they approve my application, function me() will change into the uid of the current logged user. Then what you need is to handle that query using query.wait(function(rows) {});


Here is some example (put it inside <script> tag):


FB.Event.subscribe('auth.login', function(response) {//used to handle the even of login

var query = FB.Data.query("SELECT name,email FROM user WHERE uid = me()");

query.wait(function(rows) {//inside the curly bracket is the code that will be executed when you successfuly run the query

login_by = document.getElementById("fb_login");

login_by.innerHTML = "Welcome "+rows[0].name+","

+"You have been logged in using your facebook account."

+"You already aggred for us to access your email "+rows[0].email;

});

});


Here is the HTML code:


<div id="fb_login"></div>


You can combine the above code with my previous post. As a result, after the user login and agree about the application you can get the email and username.

FQL (Facebook Query Language) FQL (Facebook Query Language) FQL (Facebook Query Language)

FQL (Facebook Query Language) FQL (Facebook Query Language) FQL (Facebook Query Language)

FQL (Facebook Query Language)

word word

FQL (Facebook Query Language)

FQL (Facebook Query Language)

FQL (Facebook Query Language)