0
$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);
}
4

1 回答 1

2

您可以picture在第一次通话中直接获取该字段。尝试这个-

/search?q=watermelon&type=post&fields=from.picture
于 2013-09-18T04:49:08.300 回答