2013-04-12 78 views
0

我想以一種用戶友好的方式顯示來自Facebook的查詢結果。Facebook查詢結果顯示

例如,Ii想要顯示照片而不是鏈接。

這裏是我的代碼:

//fql query example using legacy method call and passing parameter 

try{ 
$fql = "select name, hometown_location, sex, pic_square from user where uid=" . $user; 
$param = array(
'method' => 'fql.query', 
'query' => $fql, 
'callback' => '' 
); 
$fqlResult = $facebook->api($param); 

} 
catch(Exception $o){ 
d($o); 

} 

當我做print_r,以下將顯示爲:

FQL Query Example by calling Legacy API method "fql.query" Array ([0] => Array ([name] => Mohamed Abdelrahman [hometown_location] => [sex] => male [pic_square] => http://profile.ak.fbcdn.net/hprofile-ak-prn1/623888_100000415601915_463726603_q.jpg)) 

或當我使用:

foreach ($fqlResult as $a => $b) 
{ 

print "$a: $b\n"; 
} 

它輸出:

0: Array 

感謝所有爲你的答案我已經解決了這個自己,這裏是soulation

foreach($fqlResult as $inner_arr) 
foreach($inner_arr as $value) 
echo "$value<br/>"; 
+0

你當你的var_dump $ fqlResult在屏幕上什麼呢? –

+0

'FQL Query Example by calling Legacy API method「fql.query」Array([0] => Array([name] => Mohamed Abdelrahman [hometown_location] => [sex] =>男性[pic_square] => http:/ /profile.ak.fbcdn.net/hprofile-ak-prn1/623888_100000415601915_463726603_q.jpg))' –

回答

0

請使用更新的方法和代碼

//run fql query 
    $fql_query_url = 'https://graph.facebook.com/' 
     . 'fql?q=SELECT+uid2+FROM+friend+WHERE+uid1=me()' 
     . '&access_token=' . $access_token; 
    $fql_query_result = file_get_contents($fql_query_url); 
    $fql_query_obj = json_decode($fql_query_result, true); 

您可以在https://developers.facebook.com/docs/technical-guides/fql/

+0

我不希望print_r另一個靈魂,請不要它 –

0
遵循完全教程

FQL Query Example by calling Legacy API method "fql.query" Array ([0] => Array ([name] => Mohamed Abdelrahman [hometown_location] => [sex] => male [pic_square] => http://profile.ak.fbcdn.net/hprofile-ak-prn1/623888_100000415601915_463726603_q.jpg))

就你的情況而言,$fqlResult是你的數組。 $a是您的密鑰[0]和相應的值$b是包含name,hometown_location,sexpic_square的數組。

如果你想顯示照片這個$fqlResult,你會想你的IMG SRC設置爲$b['pic_square']

+0

如何?我想要所有的值沒有鍵不只是 它顯示圖像 解析錯誤:語法錯誤,意外的T_ENCAPSED_AND_WHITESPACE,期待T_STRING或T_VARIABLE或T_NUM_STRIN –