我想要关于好友列表的详细信息,如下面的代码
if (FBSession.activeSession.isOpen) {
[[FBRequest requestForMyFriends] startWithCompletionHandler:
^(FBRequestConnection *connection,
NSDictionary<FBGraphUser> *user,
NSError *error) {
if (!error) {
NSString *friendnames=[NSString stringWithFormat:@"Hello %@!", user.friendsnames];
}}];
}
有人可以帮忙解决这个问题吗?
答案 0 :(得分:6)
在我的应用程序中,我正在这样做:
[self.facebook requestWithGraphPath:@"me/friends?fields=name,picture,installed" andDelegate:self];
if ([request.url hasSuffix:@"me/friends?fields=name,picture,installed"])
{
NSMutableArray *array = [NSMutableArray array];
for (NSDictionary *dict in [result objectForKey:@"data"])
{
FacebookUser *friend = [[FacebookUser alloc] initWithDictionary:dict];
[array addObject:friend];
}
NSLog(@"%@", result);
希望它有所帮助, 的马里奥强>
<强>编辑:强>
这是我创建的模型,它实现了NSObject
<强> FacebookUser.h 强>
#import <Foundation/Foundation.h>
@interface FacebookUser : NSObject
@property (readonly) NSString *facebookID;
@property (readonly) NSURL *link;
@property (readonly) NSString *name;
@property (readonly) NSString *pictureURL;
@property (readonly) NSString *firstName;
@property (readonly) NSString *lastName;
<强> FacebookUser.m 强>
#import "FacebookUser.h"
@implementation FacebookUser
@synthesize facebookID = _facebookID;
@synthesize link = _link;
@synthesize name = _name;
@synthesize pictureURL = _pictureURL;
@synthesize firstName = _firstName;
@synthesize lastName = _lastName;
- (id)initWithDictionary:(NSDictionary *)dictionary;
{
self = [super init];
if (self)
{
_facebookID = [dictionary valueForKey:@"id"];
//IMPLEMENT WHAT YOU WANT TO SAVE....
}
return self;
}
@end