-6

I want the details about the friendlist like the below code

if (FBSession.activeSession.isOpen) {
    [[FBRequest requestForMyFriends] startWithCompletionHandler:
     ^(FBRequestConnection *connection,
       NSDictionary<FBGraphUser> *user,
       NSError *error) {
         if (!error) {
            NSString *friendnames=[NSString stringWithFormat:@"Hello %@!", user.friendsnames];
         }}];

}

can anyone please help with this code?

4

1 回答 1

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;

脸书用户.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
于 2012-09-07T11:19:46.327 回答