Is it possible to get messages from specific user?
If I would like to get all messages where recipients are myself and x
I didn't find a way to create that kind of query, so is it possible?
var fbid = your_fbuid_here;
FB.api({
method: 'fql.query',
query: 'SELECT thread_id, author_id, created_time FROM message WHERE thread_id IN (SELECT thread_id FROM thread WHERE folder_id = 0) AND author_id = ' + fbid + ' ORDER BY created_time ASC LIMIT 1'
}, function ( threadresponse ) {
FB.api({
method: 'fql.query',
query: 'SELECT thread_id, body, author_id, created_time FROM message WHERE thread_id = ' + threadresponse[0].thread_id + ' ORDER BY created_time ASC'
}, function ( inboxresponse ) {
//do stuff here with results
});
});
or you can do this
var fbid =the _freind_fb_uid_here;
FB.api({
method: 'fql.query',
query: 'SELECT thread_id, body, author_id, created_time FROM message WHERE thread_id IN (SELECT thread_id FROM thread WHERE folder_id = 0) AND author_id = ' + fbid + ' ORDER BY created_time DESC'
}, function ( threadresponse ) {
//do stuff here with results
});
facebookfacebook-fqlfacebook-apifacebook-graph-apifacebook-fql-query
Now FQL don't have field author_id, only originator and snippet_author. But this fields contain wrong data. For example, userA send me (userB) message: userA create thread. Anyway I see, that originator have me (userB).
Best way use recipients:
SELECT recipients,snippet,object_id,updated_time,unread,unseen,thread_id FROM thread WHERE folder_id=0 AND recipients IN (userA_fid, userB_fid)
But it's also don't work and return empty data...
Related
I am new to Facebook development and I am playing around with some proof of concepts. How would I write a query to get a list of all my friends that like the U2 page?
I am thinking something like this.
var result = fb.Get("fql", new { q = "SELECT name FROM user WHERE uid IN (SELECT uid1 FROM friend WHERE uid2=me()) AND 'U2' IN like" });
also checkins
var result = fb.Get("fql", new { q = "SELECT checkin_id, author_uid, page_id FROM checkin WHERE author_uid IN (SELECT uid2 FROM friend WHERE uid1 = me()) AND page_id IN (SELECT page_id FROM page WHERE name = 'MyPlace')" });
Also is there a query builder tool?
This should do it (example is with the PHP SDK (v3.x) )
$page_id = ID OF PAGE
$result = $facebook->api(array(
'method' => 'fql.multiquery',
'queries' => array(
'friends_liking_page' => 'SELECT uid, page_id FROM page_fan WHERE uid IN (SELECT uid2 FROM friend WHERE uid1 = me()) AND page_id = ' . $page_id,
'result' => 'SELECT uid, name, pic FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1 = me() AND (uid2 IN (SELECT uid FROM #friends_liking_page)))'
)
));
you'll need user_likes and friends_likes permission
This is my code but doesn't work:
FB.api(
{
method: 'fql.query',
query: 'SELECT uid, first_name, last_name FROM user WHERE uid=100002306311953'
},
function(data) {
alert(data.uid);
}
);
});
I get "undefined" in the alert.
Why ?
Welcome to SO!
You can use the FB.api function by passing the fql.query method and the query,
A simple query that returns the current user, name:
FB.api({
method: 'fql.query',
query: 'SELECT uid, name FROM user WHERE uid = me()'
}, function(data) {
console.log(data);
var res = data[0].name;
alert(res);
}
);
FB Docs: https://developers.facebook.com/docs/reference/fql/
In a page, if I make a test fql query it works:
$fql = 'SELECT name from user where uid = ' . $user_id;
$ret_obj = $facebook->api(array(
'method' => 'fql.query',
'query' => $fql,
));
echo '<pre>Name: ' . $ret_obj[0]['name'] . '</pre>';
However if I try to run this query, it fails:
$fql2 = 'SELECT uid, name, pic_square FROM user WHERE uid in (SELECT uid2 FROM friend WHERE uid1 = me()) AND sex =male';
$ret_obj2 = $facebook->api(array(
'method' => 'fql.query',
'query' => $fql2,
));
echo '<pre>Name: ' . $ret_obj2[0]['name'] . '</pre>';
I suspect it is an auth problem, because the same fql query works in the graph api test tool!
If you want to checkout the full php code, it's the second example on this page:
https://developers.facebook.com/docs/reference/php/facebook-api/
You need just basic permissions for this query, so this is not the issue. Try adding double quotes around "male":
$fql2 = 'SELECT uid, name, pic_square FROM user WHERE uid in (SELECT uid2 FROM friend WHERE uid1 = me()) AND sex="male"';
Thanks for the support guys, the query wasn't working for 2 reasons:
1) I forgot the ; after the end of statement
2) In my code I used
`SELECT uid, name, pic_square, FROM`
instead of
`SELECT uid, name, pic_square FROM`
to get the functionality of I want for my app I need to start using FQL.
For the main stream I was using:-
$fb_news_feed = $facebook->api('/me/home');
what would be the equivelent in FQL that returns the same JSON. My current FQL is below
$fb_feed_params = array(
'method' => 'fql.query',
'query' => "SELECT post_id, actor_id, target_id, message, likes, created_time, type FROM stream WHERE filter_key = 'nf' AND is_hidden = 0 LIMIT 100",
);
$fb_news_feed = $facebook->api($fb_feed_params);
how do I get the users name etc? I'm guessing I would have to do some kind of join like you would in mysql??
This query should do it -
SELECT name, username, pic from user WHERE uid IN (SELECT actor_id FROM stream WHERE filter_key = 'nf' AND is_hidden = 0 LIMIT 100)
Alternatively you could look at doing a multiquery. More information on multiqueries can be found on the facebook developers site:
https://developers.facebook.com/docs/reference/rest/fql.multiquery/
i am using this query
$FQLQuery = 'SELECT uid, sex, pic_square FROM user WHERE uid in ('.implode(", ", $man).')';
to get uid, pic_squre, and sex of 10friends which are selected by user
and their user id is stored in $man[ ] an array
but when i see the results it is selecting all the friends of a user not the friends
only selected by a user
whats wrong?
This is what i am getting for all friends
[12] => Array
(
[uid] => 100003033556875
[sex] => female
[pic_square] => http://profile.ak.fbcdn.net/hprofile-ak-snc4/274747_1000
03033556875_306033850_q.jpg
)
You should add LIMIT clause
$FQLQuery = 'SELECT uid, sex, pic_square FROM user WHERE uid in ('.implode(", ", $man).') LIMIT 10';