0

我正在尝试从 Facebook 页面流的数组中获取图像 src。我使用 facebook php sdk 和以下 FQL 多查询查询表:

$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

1 回答 1

0

未经测试的php代码:

$query = "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";
$response = $facebook->api('/fql?q='.$query);
$posts = $response["data"];

foreach($posts as $post){
   //do stuff

   //check to see if theres an image
     if(isset($post["attachment"]["media"]) and is_array($post["attachment"]["media"])){
          //lets get the first image only!
         $first_pic = $post["attachment"]["media"][0];
         //here's the src of the first picture!
         $src = $first_pic["src"];
         echo "<img src='$src' />";
    }else{
         echo "There is no attached picture!";
    }
} 
于 2012-12-10T20:25:56.607 回答