我試圖從Facebook頁面流的數組中獲取圖像src。 我查詢使用Facebook PHP SDK中的表和以下FQL multiquery:facebook php sdk show img src from array
$query=array(
"query1"=>"SELECT actor_id, attachment.media, app_data, description, message, permalink, likes.count, created_time, comments.count, action_links, attachment, type FROM stream WHERE source_id = 294546637313646 AND type > 0 limit 50",
"query2"=>"SELECT name, page_id FROM page WHERE page_id IN (SELECT actor_id FROM #query1)");
$response=$facebook->api(array(
'method' => 'fql.multiquery',
'queries' => $query
));
$posts = $response[0]['fql_result_set'];
$author = $response[1]['fql_result_set'];
這讓我有這一個數組:
[4] => Array
(
[actor_id] => 294546637313646
[attachment] => Array
(
[media] => Array
(
[0] => Array
(
[href] => http://www.facebook.com/photo.php?fbid=306133272821649&set=a.306133049488338.53827.294546637313646&type=1&relevant_count=1
[alt] => Test Amp Picture
[type] => photo
[src] => http://photos-a.ak.fbcdn.net/hphotos-ak-prn1/69480_306133272821649_877073836_s.jpg
[photo] => Array
(
[aid] => 294546637313646_53827
[pid] => 294546637313646_561094
[fbid] => 306133272821649
[owner] => 294546637313646
[index] => 1
我想呼應圖片src ,但無法解決如何去做。
我試過有: $pics = $posts[0]['fql_result_set'];
然後 echo "<img src={$pics['src']} />";
但不起作用。
請任何幫助,將感激地收到。
感謝
我看你的陣列,或者至少你已經證明這一點,與指數4,我猜你將需要訪問的開始那索引:'$ posts [4] ['attachment'] ['media'] [0] ['src']' – Dale
嗨戴爾,陣列從0開始,但直到4,沒有圖像。我正在循環使用'for each',所以期待什麼都沒有,直到4. –
我想你需要有一些異常處理,爲此! –