从相册中获取20张最近的照片(JSON)



我正在尝试使用以下JSON提要从相册中获取最近的20张照片:(链接)

我的代码目前工作,唯一的问题是他们不是最近的照片从相册:

<?php
    $pic_url = "https://graph.facebook.com/10151316456544622/photos?fields=picture,name,source,created_time&limit=20"; //change limit to allow more items
    $pictures = json_decode(file_get_contents($pic_url));
    $countpic= sizeof ($pictures->data); // get the number of pics for later use
    for($p=0; $p<$countpic; $p++):
        $thumb_url = "https://graph.facebook.com/".$pictures->data[$p]->id."/picture";
        $thumb = $pictures->data[$p]->source;
?>
    <li>
        <a href="<?php echo $thumb_url; ?>" class="fresco hover" data-fresco-group="facebook" data-fresco-caption="<?php echo $pictures->data[$p]->name; ?>">
            <div><div class="hover"></div><img style="width: 225px; height:250px;" title="<?php echo $pictures->data[$p]->name; ?>" alt="<?php echo $pictures->data[$p]->name; ?>" src="<?php echo $thumb_url; ?>"></div>
        </a>
    </li>
<?php endfor; ?>

而不是从图形API获取结果,你可以考虑使用FQL,这更适合于你所拥有的情况。您可以在类似于Graph API的album中查询photos FQL(文档),也可以按created时间递减顺序排序,以便您将获得最近的一个。查询类似于

select src,created,caption from photo where album_object_id=10151316456544622 
order by created desc limit 20

你可以通过这个链接查看。

此外,我希望您通过一些访问令牌访问Facebook的资源,只是为了防止在以后阶段出现任何错误。你可以使用App Access令牌,因为这看起来是公开可用的数据。

最新更新