How to show Facebook friends list on Ios with Swift

Asked

Viewed 245 times

1

I would like to know how I show a list with my facebook friends using the facebook SDK for IOS and with Swift. I’ve already done the installation and I’m already logging in on facebook. I’m just not able to show my friends list.

  • 1

    You’re already logging in to the application or the question involves the whole process (which is a bit long), including installing the SDK?

  • I’ve already done the installation and I’m already logging in on facebook. I’m just not able to show my friends list.

  • I voted to reopen, but maybe you can put these details in the question itself, enough edit, so you might understand that it’s not too wide.

  • Adjustments made

  • If you already have some code that you tried to make work but failed is always valid too.

  • I don’t have Otávio, I saw some examples and OC but I couldn’t do anything like that in Swift.

Show 1 more comment

1 answer

0


From the Graph API 2.0, the full list of friends is no longer 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 permission from the user as soon as you perform the authentication. Just the proper key for such:

user_friends

With this permission accepted by the user, 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 possess in vector friends the list of friends, and then just assemble your list of friends.

In this response from Soen has some alternatives to search for all friends, regardless of whether the friend owns or not their application, which is based on using the endpoints /me/taggable_friends and /me/invitable_friends of API. But since I don’t know your app, I don’t know if it fits these alternatives.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.