2011-11-11 34 views
0

我提出和FQL查询,并将其保存到一个数组提取值

$resultposts = $facebook->api(array('method' => 'fql.query', 
    'query' => $fqlQueryposts)); 

要提取的名称值我用这个:

echo $resultposts['first_name']; 

但我有问题“媒体“数组,它是”附件“数组。这是结构:$resultposts>attachment>media>

我应该从“媒体”数组中提取“type”,“src”和“href”值。

我试过这样:

$resultposts['attachment']['media']['type']; 

但它不工作。错误是“未定义索引:类型”。

我该怎么办?谢谢

回答

0

这篇文章有点旧,但是当我在搜索同一个问题时偶然发现了它,并找到了答案,我会将它分享给其他人。

使用PHP SDK(3.11)

$attachment = $facebook->api(array('method' => 'fql.query', 'query' => 'SELECT attachment FROM stream WHERE post_id = "'.$poid.'"')); 

foreach($attachment as $attach) 
{ 
    foreach($attach as $i => $o) 
    { 
     echo $o['name']; 

     foreach($o['media'] as $t => $y) 
     { 
      echo $y['type']; 
     } 
    } 
}