我的Facebook SDK工作正常,但我不确定如何获取Facebook好友及其ID的列表?
我找到了这段代码,但它似乎没有用,有人可以告诉我如何访问名称和ID列表吗?
// 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
在以下行中,我可以通过将0..<data.count
替换为0...data.count
来修复错误,这会改变什么吗?
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")
}
它应该返回如下数据:
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;
};
}
此外,在“摘要”中,我得到了正确数量的朋友,但这似乎没有转移到别处,例如当我尝试打印朋友的数量时。