我正在使用facebook连接我的iphone应用程序。它能够对用户进行身份验证,并在用户的墙上发布评论。但我不知道如何检索用户的好友列表。我们非常感谢示例代码。
提前致谢,
-Chandni
答案 0 :(得分:3)
在实现FBRequestDelegate和FBSessionDelegate的类中执行此操作:
-(void) getFriends{
NSString * funcName = @"friends.get";
[[FBRequest requestWithDelegate:self] call:funcName params:nil];
}
- (void) processFriendsQuery:(id) result{
friends = [[NSMutableArray alloc] init];
NSString * element;
gDatabase.userIdList = [[[NSMutableArray alloc] initWithCapacity:MAX_FRIENDS_LIST] autorelease];
for (element in result){
Friend * aFriend = [[[Friend alloc] init]autorelease];
NSString * uid = [self dictionaryToUID:element];
aFriend.userId = (NSMutableString *) uid;
[gDatabase.userIdList addObject:aFriend.userId];
}
然后在
中调用它- (void)request:(FBRequest*)request didLoad:(id)result {
[self processFriendsQuery:result];
}
答案 1 :(得分:0)
使用此方法调用getFriends
方法
- (void)request:(FBRequest*)request didLoad:(id)result
答案 2 :(得分:0)
这是我将一个朋友列表输出到控制台所做的。我还在试图弄清楚如何向他们的一面墙发送消息......
AppDelegate *delegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
//Call the request method
[[delegate facebook] requestWithGraphPath:@"me/friends" andDelegate:self];
// get the array of friends
NSArray *data = [result objectForKey:@"data"];
// Check that the user has friends
if ([data count] > 0) {
NSMutableArray *array = [NSMutableArray array];
for (int i = 0; i < data.count; i++){
id object = [data objectAtIndex:i];
[array addObject:[object objectForKey:@"name"]];
}
NSLog(@"list of friends %@", array);