使用 PHP 和 graph api 照片显示来自 facebook 的图像
我正在尝试显示我的 Facebook 粉丝页面上的照片缩略图。我研究了 facebook dev 和 graph 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 />";
}
I am trying to show my thumbnails of photos from my facebook fan page. I have studied the facebook dev and graph api. Now I am trying to using php to automate the process and show the images on my photo page.
$facebook_album = file_get_contents("https://graph.facebook.com/10150101465621686/photos");
which returns the following data with the image data repeating for each image (see below):
{
"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"
},
My questions is... Is there an easy way to put the following info in an array that will be easy to loop through?
Something like so that it loops through the data and puts the value of picture in the image src.
foreach( $facebook_album as $key => $value){
echo "<img src='picture'/><br />";
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
为什么不尝试 json 数据的 json_decode 呢?
http://php.net/manual/en/function.json-decode.php
$dataArr = json_decode($dataStr,true);
$imageArr = $dataArr["图像"];
Why don't you try json_decode of the json data ?
http://php.net/manual/en/function.json-decode.php
$dataArr = json_decode($dataStr,true);
$imageArr = $dataArr["images"];
这似乎对我有用
This seemed to work for me
使用以下代码(php sdk)
开始一张一张地显示照片
Use following code (php sdk)
Start showing photos one by one