如何使用FBFriendPicker从Facebook iOS api获取userID

时间:2012-08-23 06:22:04

标签: objective-c ios facebook api

我目前正在使用来自facebook api for iOS的FBFriendPicker来获取所选朋友的名字。我怎样才能同时获得朋友的用户ID。以下功能用于名称。

// Facebook integration
- (void)facebookViewControllerDoneWasPressed:(id)sender {
    NSString *text;

    // we pick up the users from the selection, and create a string that we use to update the text view
    // at the bottom of the display; note that self.selection is a property inherited from our base class
    for (id<FBGraphUser> user in self.friendPickerController.selection) {
        self.name.text = user.name;
    }

    [self dismissModalViewControllerAnimated:YES];
}

2 个答案:

答案 0 :(得分:1)

for (id<FBGraphUser> user in self.friendPickerController.selection) {
    NSLog(@"Name: %@ ID: %@", user.name, user.id);
}

我知道所选朋友的姓名和身份证会以这种方式显示在日志中。

所以不要使用“name”,只需使用“id”,如果你想把它用作字符串那就是.. :))

答案 1 :(得分:0)

您可以获取所有选定朋友的ID,并可以添加到数组中,如下所示:

///获取selsected friends id ////////

  • (void)facebookViewControllerDoneWasPressed:(id)sender {

    NSMutableString * text = [[NSMutableString alloc] init]; selectIDs = [[NSMutableArray alloc] init];

    //我们从选择中选择用户,并创建一个用于更新文本视图的字符串 //在显示屏的底部;请注意,self.selection是从我们的基类继承的属性 for(self.friendPickerController.selection中的id用户){

    if ([text length]) {
        [text appendString:@", "];
    }
    [text appendString:user.name];
    [selectIDs addObject:user.id];
    

    } [self dismissModalViewControllerAnimated:YES]; }