Friday, November 8, 2013

Useful FQL examples

I've been exploring the facebook graph API and fql. FQL seems to be a very powerful tool. Here are some of them which I've been using recently:

1. Finding friends user id by looking up his name:

select name, uid from user where strpos(name, "part_of_your_friends_name") >= 0 and uid in (SELECT uid2 FROM friend WHERE uid1=me())

2. Find the id of a group by its name:

select id, name from profile where name="group_name"

3. Find posts of a user in a group:

SELECT post_id, message, created_time  FROM stream WHERE strpos(field_name,'possible_string') >=0 and  source_id=group_Id and actor_id=user_id  and created_time >=unix_timestamp and created_time < unix_timestamp limit A_NUMBER


//will be continued...

note:
To get the unix timestamp you can use this code in Javascript:

var d = new Date();
d.setMonth(d.getMonth() - 3);
three = Math.round(d.getTime() / 1000); //3 months ago

console.log(three);



No comments:

Post a Comment