Getting list of Facebook friends with latest API Getting list of Facebook friends with latest API php php

Getting list of Facebook friends with latest API


I think this is what you want:

$friends = $facebook->api('/me/friends');


This is live version of PHP Code to get your friends from Facebook

<?php    $user = $facebook->getUser();    if ($user) {        $user_profile = $facebook->api('/me');        $friends = $facebook->api('/me/friends');        echo '<ul>';        foreach ($friends["data"] as $value) {            echo '<li>';            echo '<div class="pic">';            echo '<img src="https://graph.facebook.com/' . $value["id"] . '/picture"/>';            echo '</div>';            echo '<div class="picName">'.$value["name"].'</div>';             echo '</li>';        }        echo '</ul>';    }?>


Getting the friends like @nfvs describes is a good way. It outputs a multi-dimensional array with all friends with attributes id and name (ordered by id). You can see the friends photos like this:

foreach ($friends as $key=>$value) {    echo count($value) . ' Friends';    echo '<hr />';    echo '<ul id="friends">';    foreach ($value as $fkey=>$fvalue) {        echo '<li><img src="https://graph.facebook.com/' . $fvalue->id . '/picture" title="' . $fvalue->name . '"/></li>';    }    echo '</ul>';}