使用FacebookSDK获取Facebooklogin用户的朋友列表
我想在我的iPhone应用程序中使用FacebookSDK访问朋友列表和他们的个人资料图片。 请build议演示或代码。
FBRequest* friendsRequest = [FBRequest requestForMyFriends]; [friendsRequest startWithCompletionHandler: ^(FBRequestConnection *connection, NSDictionary* result, NSError *error) { NSArray* friends = [result objectForKey:@"data"]; NSLog(@"Found: %i friends", friends.count); for (NSDictionary<FBGraphUser>* friend in friends) { NSLog(@"I have a friend named %@ with id %@", friend.name, friend.id); } }];
您需要使用FBRequest,requestForMyFriends方法,它会使用活动会话创build一个表示对“我/朋友”端点进行Graph API调用的请求。
FBRequest* friendsRequest = [FBRequest requestForMyFriends]; [friendsRequest startWithCompletionHandler: ^(FBRequestConnection *connection, NSDictionary* result, NSError *error) { NSArray* friends = [result objectForKey:@"data"]; NSLog(@"Found: %i friends", friends.count); for (NSDictionary<FBGraphUser>* friend in friends) { NSLog(@"My friend named %@ and id %@", friend.name, friend.id); } }];
NSArray *permissions = [[NSArray alloc] initWithObjects: @"user_birthday",@"friends_hometown", @"friends_birthday",@"friends_location", nil]; [FBSession openActiveSessionWithReadPermissions:permissions allowLoginUI:YES completionHandler:write handler code..]
[FBRequestConnection startForMyFriendsWithCompletionHandler:^(FBRequestConnection *connection, NSDictionary* result, NSError *error) { NSArray *data_array = [result objectForKey:@"data"]; //array of friends NSMutableArray *pictures = [NSMutableArray array]; // array for pictures for (NSDictionary *friend in data_array) { NSString *friend_id = friend[@"id"]; NSString *urlString = [NSString stringWithFormat:@"https://graph.facebook.com/%@/picture",friend_id]; NSURL *url = [NSURL urlWithString:urlString]; [pictures addObject:[NSData dataWithContentsOfURL:url]]; } }];
由于[NSData dataWithContentsOfURL:url]
相当慢,你可以考虑在后台运行这个代码
- 如何在iOS应用程序中创buildFacebook注册function?
- Facebook提供安全警告:请按照您的密码处理上述URL,不要与任何人分享
- 在UIWebView中播放Facebookvideo
- 用Facebooklogin并获取iOS 7的电子邮件和用户信息
- 如何使用Facebook Graph API和facebook ios sdk获取完整的用户对象?
- 升级到SDK 4.1后,Facebooklogin失败(总是被取消)
- iOS上的Chrome上的Facebook OAuth“不支持”
- 我怎样才能得到用户信息使用Facebook的SDK 4.1在iOS?
- Facebook IOS SDK 3.1.1与Xcode 4.5.2错误