【问题标题】:how to retrieve friends' list using facebook connect with iphone app如何使用 facebook connect with iphone app 检索好友列表
【发布时间】:2010-01-23 02:14:46
【问题描述】:

我正在为我的 iphone 应用程序使用 facebook connect。它能够对用户进行身份验证,并在用户的墙上发表评论。但我不确定如何检索用户的好友列表。示例代码将不胜感激。

提前致谢,

-Chandni

【问题讨论】:

    标签: iphone facebook


    【解决方案1】:

    在实现 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];    
    }
    

    【讨论】:

    • 非常感谢!!!我今天会尝试.. 另外我假设 FBConnect 没有任何默认页面来显示 iPhone 的朋友列表,他们必须发布和登录
    • 大卫将调用 getFriends 方法
    【解决方案2】:

    这就是我将好友列表输出到控制台的操作。不过,我仍在试图弄清楚如何向他们的一面墙发送消息......

     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);
    

    【讨论】:

      【解决方案3】:

      使用这个方法调用你的getFriends方法

      - (void)request:(FBRequest*)request didLoad:(id)result
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-04-22
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多