[英]how to retrieve friends' list using facebook connect with iphone app
我的iPhone应用程序使用的是Facebook Connect。 它能够对用户进行身份验证,也可以在用户的墙上发布评论。 但是我不确定如何检索用户的朋友列表。 样例代码将受到高度赞赏。
提前致谢,
-钱德尼
在实现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];
}
这是我将朋友列表输出到控制台的操作。 我仍在尝试找出如何向他们的一面墙发送消息...
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);
使用此方法调用您的getFriends
方法
- (void)request:(FBRequest*)request didLoad:(id)result
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.