2012-09-03 119 views
0

我當前的查詢顯示從指定時間發佈在牆上的一些消息。顯示實際名稱而不是uid

$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

首先在命令行檢查您的查詢。 – Nishant

+0

是的,我知道這是行不通的。在FQL中進行一些查詢並使其顯示您想要的輸出非常困難。 – MegaNairda

+0

嘗試facebook multiquery ... – Abhishek

回答

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'來獲取頁面細節。

0

,因爲這可以使用JOIN是可能的,但FQL沒有按」 t支持連接:

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]) 
+0

您的查詢存在的問題是郵件在輸出中丟失。 – MegaNairda

+0

@MegaNairda我已更新,請檢查此項。 – Vinay

+0

我其實不知道如何應用你的代碼。它是多重查詢嗎?請詳細說明我將如何使用它 – MegaNairda

相關問題