Find Facebook friends in swift
I have the Facebook SDK working, but I'm not sure exactly how to get the list of Facebook friends and their IDs?
I found this code but it doesn't seem to work, can anyone show me how to access the list of names and ids?
// Get List Of Friends
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
There is an error on the next line that I can fix by replacing 0..<data.count
with 0...data.count
, does that change anything?
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")
}
It should return data like:
Result Dict: {
data = (
{
"first_name" = Brian;
id = <FACEBOOK FRIEND FACEBOOK ID>;
"last_name" = Coleman;
name = "Brian Coleman";
}
);
paging = {
next = "https://graph.facebook.com/v2.0/<LOGGED IN FACEBOOK USER ID>/friends?fields=id,name,first_name,last_name&format=json&access_token=<FACEBOOK TOKEN USED BY YOUR APP>&offset=5000&__after_id=<ENCREYPTED ID>";
};
summary = {
"total_count" = 1;
};
}
Also, in the "resume" I get the right number of friends, but this is not like transferring elsewhere, such as when I try to type the number of friends.
+3
source to share
No one has answered this question yet
Check out similar questions: