4

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?

Kara
  • 5,650
  • 15
  • 48
  • 55
242Eld
  • 215
  • 2
  • 5
  • 13
  • possible duplicate of [Fetching list of friends in Graph API or FQL - Appears to be missing some friends](http://facebook.stackoverflow.com/questions/11135053/fetching-list-of-friends-in-graph-api-or-fql-appears-to-be-missing-some-friend) – Igy Feb 15 '13 at 01:25
  • @Igy Im not sure it's a duplicate, and if so then my results are still significantly lacking. what about thge "next" page whom I can't access. putting in `limt = 0`, either way I'll be happy for some better explanation of that, and, if there's at least a way to get the number of the user's friend count – 242Eld Feb 18 '13 at 22:54
  • 1
    For friend count, FQL: `select friend_count from user where uid = me()` - in the absence of further info i still think the issue is due to he behaviour in the question i marked as dupe – Igy Feb 19 '13 at 00:14
  • See the answer here See the answer here http://stackoverflow.com/questions/23417356/facebook-graph-api-v2-0-me-friends-returns-empty-or-only-friends-who-also-use-m#answer-23417628 – Dieter Pisarewski May 22 '14 at 15:45

2 Answers2

1

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

Adriano Godoy
  • 1,230
  • 10
  • 21
-1

You just try this..

This is very simple to you can get all friend count in a single line :)

@graph = Koala::Facebook::API.new(facebook_token)
@friends = @graph.get_connection("me", "friends",api_version:"v2.0").raw_response["summary"]["total_count"]
Karthick Nagarajan
  • 1,335
  • 2
  • 14
  • 26