Search code examples
facebookfacebook-graph-apikoala

Getting list of friends with koala and fb api


Im trying to return the friend list with uid of an authenticated user. however I only get a partial return value, some part of the friends are just left out:

graph = Koala::Facebook::API.new(fb_token)
friends = graph.get_connections("me", "friends")
#some friend action

when I type in the

friends.paging["next"]

in the browser it also returns an empty json array

   "data": [    ]

How am I doing it wrong and what is the correct practice?


Solution

  • You need to get the permission 'user_friends' to get friendlist, otherwise you'll receive a empty data:

    The field 'friends' is only accessible on the User object after the user grants the 'user_friends' permission.

    Try yourself: https://developers.facebook.com/tools/explorer?method=GET&path=me%2Ffriends&version=v2.5

    So, with correct permission you can do:

    graph = Koala::Facebook::API.new(fb_token)
    result = graph.get_connections('me', 'friends')
    

    to paginate:

    next_page = result.next_page
    

    LAST BUT NOT LEAST:

    Only friends who installed this app are returned in API v2.0 and higher. total_count in summary represents the total number of friends, including those who haven't installed the app.Learn More