使用PHP和图API照片显示来自Facebook的图像

我正在尝试显示来自我的Facebook粉丝页面的照片缩略图.我研究了Facebook开发和图形API.现在,我正在尝试使用php来自动化过程,并在我的照片页面上显示图像.

$facebook_album = file_get_contents("https://graph.facebook.com/10150101465621686/photos");

它会返回以下数据,并为每个图像重复图像数据(请参见下文):

{
   "data": [
      {
         "id": "10150101465701686",
         "from": {
            "name": "Lingua Language Academy",
            "category": "Organization",
            "id": "55206251685"
         },
         "picture": "http://photos-d.ak.fbcdn.net/hphotos-ak-ash4/185883_10150101465701686_55206251685_6497497_7724100_s.jpg",
         "source": "http://a4.sphotos.ak.fbcdn.net/hphotos-ak-ash4/185883_10150101465701686_55206251685_6497497_7724100_n.jpg",
         "height": 540,
         "width": 720,
         "images": [
            {
               "height": 540,
               "width": 720,
               "source": "http://a4.sphotos.ak.fbcdn.net/hphotos-ak-ash4/185883_10150101465701686_55206251685_6497497_7724100_n.jpg"
            },
            {
               "height": 135,
               "width": 180,
               "source": "http://photos-d.ak.fbcdn.net/hphotos-ak-ash4/185883_10150101465701686_55206251685_6497497_7724100_a.jpg"
            },
            {
               "height": 97,
               "width": 130,
               "source": "http://photos-d.ak.fbcdn.net/hphotos-ak-ash4/185883_10150101465701686_55206251685_6497497_7724100_s.jpg"
            },
            {
               "height": 56,
               "width": 75,
               "source": "http://photos-d.ak.fbcdn.net/hphotos-ak-ash4/185883_10150101465701686_55206251685_6497497_7724100_t.jpg"
            }
         ],
         "link": "http://www.facebook.com/photo.php?pid=6497497&id=55206251685",
         "icon": "http://static.ak.fbcdn.net/rsrc.php/v1/yz/r/StEh3RhPvjk.gif",
         "created_time": "2011-02-22T02:41:02+0000",
         "position": 1,
         "updated_time": "2011-02-22T02:41:04+0000"
      },

我的问题是…是否有一种简单的方法将以下信息放入容易循环的数组中?

诸如此类的东西使它循环遍历数据并将图片的值放在图像src中.

foreach( $facebook_album as $key => $value){
    echo "<img src='picture'/><br />";
}

解决方法:

为什么不尝试json数据的json_decode呢?

http://php.net/manual/en/function.json-decode.php

$dataArr = json_decode($dataStr,true);

$imageArr = $dataArr [“ images”];

上一篇:Django之request进入中间件《二》


下一篇:s000ys