Get Facebook friends list in Swift
Here is what I ended up doing. Unlike the first 2 permissions, I had to make a separate request to get the friends:
FBRequestConnection.startForMyFriendsWithCompletionHandler({ (connection, result, error: NSError!) -> Void in
if error == nil {
var friendObjects = result["data"] as [NSDictionary]
for friendObject in friendObjects {
println(friendObject["id"] as NSString)
}
println("\(friendObjects.count)")
} else {
println("Error requesting friends list form facebook")
println("\(error)")
}
})
Get Friends list using below code.
var friendsRequest : FBRequest = FBRequest.requestForMyFriends()
friendsRequest.startWithCompletionHandler
{
(connection:FBRequestConnection!, result:AnyObject!, error:NSError!) -> Void in
var resultdict = result as NSDictionary
println("Result Dict: \(resultdict)")
var data : NSArray = resultdict.objectForKey("data") as NSArray
for i in 0 ..< data.count
{
let valueDict : NSDictionary = data[i] as NSDictionary
let id = valueDict.objectForKey("id") as String
println("the id value is \(id)")
}
var friends = resultdict.objectForKey("data") as NSArray
println("Found \(friends.count) friends")
}