facebook friends list getting

余生长醉 提交于 2019-12-01 08:42:11

问题


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


来源:https://stackoverflow.com/questions/25402119/facebook-friends-list-getting

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!