我当前的查询显示指定时间内发布在墙上的一些消息。
$fql = "SELECT post_id, actor_id, target_id, message FROM " .
"stream WHERE filter_key = 'others' AND created_time > 1346277600 LIMIT 50";
问题是,它只显示uid而不是在我的墙上发布消息的人的实际名称。
编辑: 我现在使用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']
));
现在我得到一个空数组,但在我的正常查询中,我得到了29
$fql = "SELECT post_id, actor_id, target_id, message FROM " .
"stream WHERE filter_key = 'others' AND created_time > 1346277600 LIMIT 50"
答案 0 :(得分:5)
使用Facebook multiquery。
它将减少对Facebook API的更多调用。您必须处理结果才能获得所需的输出。
$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);
可能是我的结果处理可能没有优化或最佳,你可以做得更好:)。
由于某些演员可能是Facebook页面,我使用'query3'来获取页面细节。
答案 1 :(得分:0)
因为这可以使用JOIN,但FQL不支持连接:
FQL FROM子句只包含一个表。您可以在SELECT或WHERE子句中使用IN关键字来执行子查询,但子查询不能引用外部查询范围中的变量。
因此,您可以先检索uid,然后检索first_name和last_name。
SELECT post_id, actor_id, target_id, message FROM stream WHERE
filter_key = 'others' AND created_time > 1346277600 LIMIT 50
然后使用它,
SELECT name FROM user WHERE uid in ($row[actor_id], $row[target_id])