$search = $facebook->api('/search?q=watermelon&type=post');
返回类似这样的内容:
{
"data": [
{
"id": "1194579494_10201162886052970",
"from": {
"name": "Dawn Rittman Stoltz",
"id": "1194579494"
},
"message": "Our first watermelon and pumpkin from the farm!!! We rock at this garden thing",
"picture": "https://fbcdn-photos-f-a.akamaihd.net/hphotos-ak-ash3/563531_10201162883172898_1559330219_t.jpg",
"link": "https://www.facebook.com/photo.php?fbid=10201162883172898&set=pcb.10201162886052970&type=1&relevant_count=2",
"icon": "https://static.xx.fbcdn.net/rsrc.php/v2/yx/r/og8V99JVf8G.gif",
"privacy": {
"value": ""
},
"type": "photo",
"object_id": "10201162883172898",
"application": {
"name": "Facebook for iPhone",
"namespace": "fbiphone",
"id": "6628568379"
}
],
"paging": {
"previous": "https://graph.facebook.com/search?type=post&q=watermelon&limit=25&since=1379461168",
"next": "https://graph.facebook.com/search?type=post&q=watermelon&limit=25&until=1379460365"
}
}
有没有比获取Facebook用户的ID更有效的方法,并提出一堆请求从api获取他们的个人资料图片?
$data = $search['data'];
$picture_urls = array();
foreach ($data as $status) {
$from = $status['from'];
$id = $from['id'];
$picture = $facebook->api('/' . $id . '/picture?type=square&redirect=false');
$picture_data = $picture['data'];
$picture_url = $picture_data['url'];
array_push($picture_urls, $picture_url);
}
答案 0 :(得分:2)
您可以在第一次通话中直接获得picture
字段。试试这个 -
/search?q=watermelon&type=post&fields=from.picture