【问题标题】:How to use FBFriendPicker to get userID from Facebook iOS api如何使用 FBFriendPicker 从 Facebook iOS api 获取用户 ID
【发布时间】:2012-08-18 15:02:51
【问题描述】:

我目前正在使用 iOS 版 facebook api 中的 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];
}

【问题讨论】:

    标签: objective-c ios facebook api


    【解决方案1】:

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

    ///获取选择的好友id////////

    • (void)facebookViewControllerDoneWasPressed:(id)sender {

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

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

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

      } [自我dismissModalViewControllerAnimated:是]; }

    【讨论】:

      【解决方案2】:
      for (id<FBGraphUser> user in self.friendPickerController.selection) {
          NSLog(@"Name: %@ ID: %@", user.name, user.id);
      }
      

      我知道选择的朋友的姓名和 ID 会以这种方式显示在日志中..

      所以不要使用“name”,而是使用“id”,如果你想将它用作字符串.. :)

      【讨论】:

        猜你喜欢
        • 2011-11-13
        • 1970-01-01
        • 1970-01-01
        • 2014-11-21
        • 1970-01-01
        • 1970-01-01
        • 2011-10-31
        • 2011-05-28
        • 1970-01-01
        相关资源
        最近更新 更多