我正在尝试从Facebook页面流的数组中获取图像src。 我使用facebook php sdk和以下FQL multiquery查询表:
$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']} />";
但这不起作用。
任何帮助,请感谢。
由于
答案 0 :(得分: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!";
}
}