facebook friends list getting

2019-01-27 00:04发布

问题:

I want to get a list of friends with php. I got the necessary permissions, but I can not get a list of friends.

'scope' => 'email, user_friends'

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

result:

( [data] => Array ( ) [summary] => Array ( [total_count] => 46 ) )

回答1:

The docs at https://developers.facebook.com/docs/apps/upgrading#upgrading_v2_0_user_ids clearly states that the Graph API starting with v2.0 only returns the friends which also use the same app.

In your case apparantly nobody of your friends actually uses that app, that's why the result array is empty.

Please use the StackOverflow search the next time before you post a question which was posted here at least 100 times. Thanks.



回答2:

Here it is, buddy:

<?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>';
    }