facebook friends list getting

2019-01-27 00:08发布

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 ) )

2条回答
仙女界的扛把子
2楼-- · 2019-01-27 00:40

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.

查看更多
冷血范
3楼-- · 2019-01-27 00:43

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>';
    }
查看更多
登录 后发表回答