Getting list of Facebook friends with latest API

后端 未结 10 1178
南旧
南旧 2020-12-07 18:06

I\'m using the most recent version of the Facebook SDK (which lets to connect to something called the \'graph API\' though I\'m not sure). I\'ve adapted Facebook\'s example

相关标签:
10条回答
  • 2020-12-07 18:40

    Just a heads up for anyone stumbling across this question using v2.0 of the Graph API: This will not work anymore. In v2.0, calling /me/friends only returns a list the person's friends who also use the app:

    • A user access token with user_friends permission is required to view the current person's friends.
    • This will only return any friends who have used (via Facebook Login) the app making the request.
    • If a friend of the person declines the user_friends permission, that friend will not show up in the friend list for this person.
    0 讨论(0)
  • 2020-12-07 18:46

    If you want to use the REST end point,

    $friends = $facebook->api(array('method' => 'friends.get'));
    

    else if you are using the graph api, then use,

    $friends = $facebook->api('/me/friends');
    
    0 讨论(0)
  • 2020-12-07 18:48

    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>';
    }
    
    0 讨论(0)
  • 2020-12-07 18:49
    friends.get
    

    Is function to get a list of friend's

    And yes this is best

        $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>';
    
    0 讨论(0)
提交回复
热议问题