2012-09-07 16 views
-5

我想了解像下面的代碼如何從Facebook加載我的Facebook朋友並將它們顯示在iPhone應用程序上?

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

} 

誰能請使用此代碼幫助好友列表的詳細信息?

+2

如果你指定你期待什麼樣的幫助,有人肯定可以。 – 2012-09-07 11:07:16

回答

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 
+0

哪裏可以得到這個FacebookUser? – reji

+0

看看我在這篇文章中添加了什麼 –

+0

可以請告訴facebook用戶的[user objectForKey:]是什麼? – reji

相關問題