0

我当前的查询显示了指定时间在我的墙上发布的一些消息。

$fql = "SELECT post_id, actor_id, target_id, message FROM " .
        "stream WHERE filter_key = 'others' AND created_time > 1346277600 LIMIT 50";

问题是,它只显示 uid 而不是在我的墙上发布消息的人的实际姓名。

编辑:我现在使用多查询

$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"
4

2 回答 2

5

使用 Facebook 多查询。

它将减少对 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”来获取页面详细信息。

于 2012-09-03T06:56:11.880 回答
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])
于 2012-09-03T05:49:05.267 回答