Using the Facebook Graph API to get a list of a user's friends

后端 未结 3 946
说谎
说谎 2020-12-13 01:03

I need to get a hold of a user of my app\'s list of friends to filter the users that show up in a friend picker. I know I can call the following and get the list:

         


        
3条回答
  •  佛祖请我去吃肉
    2020-12-13 02:02

    UPDATE: As per the changes introduced in V2.0, /me/friends will return app friends only.


    The right way to do that is by using the Facebook Javascript-SDK, something like this:

    function getFriends() {
        FB.api('/me/friends', function(response) {
            if(response.data) {
                $.each(response.data,function(index,friend) {
                    alert(friend.name + ' has id:' + friend.id);
                });
            } else {
                alert("Error!");
            }
        });
    }
    

    Please note that:

    1. I'm using jQuery here too
    2. You may need to check if the user is connected before calling this function.

提交回复
热议问题