Getting friends list with koala and fb api

I am trying to return a friends list with an uid of an authenticated user. however, I get only a partial return value, some friends are simply missing:

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

when i type

 friends.paging["next"] 

in the browser it also returns an empty json array

  "data": [ ] 

How am I doing this wrong and what is the right practice?

+4
source share
2 answers

You need to get permission "user_friends" to get a list of friends, otherwise you will get empty data:

The friends field is available only for the User object after the user grants user_friends permission.

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

So, with the right resolution, you can do:

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

for pagination:

 next_page = result.next_page 

LAST, BUT NOT LESS:

Only users who install this application will return to API version 2.0 and higher. The total_count in the summary represents the total number of friends, including those who did not install the application. More details ...

+1
source

You just try it.

It is very simple, you can get all your friends accounts in one line :)

 @graph = Koala::Facebook::API.new(facebook_token) @friends = @graph.get_connection("me", "friends",api_version:"v2.0").raw_response["summary"]["total_count"] 
-1
source

All Articles