How to show Facebook friends list on ios with Swift

1

I would like to know how I display a list with my facebook friends using the facebook SDK for IOS and Swift. I have already installed it and I am already logging in via facebook. I just can not show my friends list.

    
asked by anonymous 14.05.2015 / 16:13

1 answer

0

From the Graph API 2.0 , the complete list of friends is not more allowed by default in authentication and only returns friends who have authorized, ie those who also own your application.

So, first of all, you need to ask the user for permission as soon as you authenticate. Just the right key for it:

  

user_friends

With this user-accepted permission, you can then make the request:

var friendsRequest : FBRequest = FBRequest.requestForMyFriends()
friendsRequest.startWithCompletionHandler{(connection:FBRequestConnection!, result:AnyObject!, error:NSError!) -> Void in
    var resultdict = result as NSDictionary
    var friends = resultdict.objectForKey("data") as NSArray
}

With this, you will have the list of friends in the% vector, and then just put together your friends list.

This SOen answer has some alternatives to fetch all friends, regardless of whether the friend has or does not have your app, which is based on using the endpoints friends and /me/taggable_friends API . But as I do not know your application, I do not know if it fits into these alternatives.

    
15.05.2015 / 16:15