Reputation: 839
My current query display some of the messages posted on my wall from a specified time.
$fql = "SELECT post_id, actor_id, target_id, message FROM " .
"stream WHERE filter_key = 'others' AND created_time > 1346277600 LIMIT 50";
Problem is, it only display the uid instead of the actual name of the one who posted the message on my wall.
EDIT: I now use multiquery
$fql = "{" .
"\"user_stream\" : \"SELECT post_id, actor_id, target_id, message FROM stream WHERE " .
" filter_key = 'others' AND created_time > 1346277600 LIMIT 50 \"" .
"\"actor_info\" : \"SELECT uid, name FROM user " .
" WHERE uid IN (SELECT actor_id, target_id FROM #user_stream)\"" .
"}";
$data['msgs'] = $this->facebook->api(array(
'method' => 'fql.multiquery',
'queries' => $fql,
'access_token'=>$facebook['access_token']
));
Now I get an empty array but on my normal query I get 29
$fql = "SELECT post_id, actor_id, target_id, message FROM " .
"stream WHERE filter_key = 'others' AND created_time > 1346277600 LIMIT 50"
Upvotes: 0
Views: 929
Reputation: 836
Use Facebook multiquery.
It will reduce more calls to Facebook API. You will have to process the result to get required output.
$multiQuery = array(
"query1" => "SELECT actor_id, message FROM stream WHERE filter_key = 'others' AND created_time > 1346277600 LIMIT 50",
"query2" => "SELECT uid,first_name, last_name FROM user WHERE uid in (SELECT actor_id FROM #query1)",
"query3" => "SELECT page_id,name FROM page WHERE page_id in (SELECT actor_id FROM #query1)",
);
$param = array(
'method' => 'fql.multiquery',
'queries' => $multiQuery,
'callback' => '');
$queryresults = $facebook->api($param);
$result = array();
foreach($queryresults[0]['fql_result_set'] as $message){
$message_ = $message;
$actor_ = 'page';
foreach($queryresults[1]['fql_result_set'] as $actor){
if($actor['uid'] == $message['actor_id']){
$actor_ = $actor;
break;
}
}
if($actor_ == 'page'){
foreach($queryresults[2]['fql_result_set'] as $actor){
if($actor['page_id'] == $message['actor_id']){
$actor_ = $actor;
break;
}
}
}
$result[] = array('message'=>$message_,'actor'=>$actor_);
}
print_r($result);
May be my result processing may be not optimized or best, you can make it better :) .
As some actors can be Facebook pages, i am using 'query3' to fetch page detail.
Upvotes: 5
Reputation: 2594
As this can be possible using JOIN but FQL doesn't support joins:
FQL FROM clause contain only a single table. You can use the IN keyword in SELECT or WHERE clauses to do subqueries, but the subqueries cannot reference variables in the outer query's scope.
So you can retrieve uid first, then retrieve first_name and last_name.
SELECT post_id, actor_id, target_id, message FROM stream WHERE
filter_key = 'others' AND created_time > 1346277600 LIMIT 50
Then use this,
SELECT name FROM user WHERE uid in ($row[actor_id], $row[target_id])
Upvotes: 0