【问题标题】:iOS Facebook friends list - image url, user id, nameiOS Facebook 好友列表 - 图片网址、用户 ID、姓名
【发布时间】:2013-04-02 04:17:26
【问题描述】:

在 iOS facebooks SDK 中,我想获取 facebook 用户 ID、朋友姓名和图像 URL(用户个人资料图片)。

问题:

  1. 我用过 FBFriendPickerViewController,它会显示朋友的名字,但是有什么方法可以获取图片 URL 和 facebook id。

  2. FBFriendPickerViewController 也是实际列出朋友列表的正确方法。或者我应该使用其他 API。

【问题讨论】:

  • 你在使用graphApi吗?
  • 如何检查图形 API 是否正在使用。原谅我的无知。
  • 我将发布一个答案请检查...我认为它对你有帮助:)

标签: ios facebook facebook-graph-api


【解决方案1】:
FBRequest* friendsRequest = [FBRequest requestForMyFriends];

[friendsRequest startWithCompletionHandler: ^(FBRequestConnection *connection,NSDictionary* result,NSError *error)
 {
     NSArray* friends = [result objectForKey:@"data"];

     for (NSDictionary<FBGraphUser>* friend in friends)
     {
         NSLog(@"friend id = %@", friend.id);
         NSLog(@"friend name = %@", friend.username);
         NSLog(@"friend pic url = %@", [NSString stringWithFormat:@"https://graph.facebook.com/%@/picture?", friend.id]);

     }
 }];

参考 - How to get the list of friend without opening FBFriendPickerViewController iOS

【讨论】:

    【解决方案2】:

    First U down load the classes from this link and this link help for u

    //Need to declare
    **@property (nonatomic, retain)**
    
     FbGraph *fbGraph;
     UserProfile *profil_obj;
     MBProgressHUD *HUD;
    
    
     -(IBAction)FacebookButtonPressed
    {
    
       if([[NSUserDefaults standardUserDefaults] boolForKey:@"isLogin"]==NO)
        {
        }
       else
          {
    
        HUD=[MBProgressHUD showHUDAddedTo:self.view animated:YES];
        [HUD setLabelText:@"Loading Profile..."];
    
           }
       NSString *client_id = @"********";
       self.fbGraph = [[FbGraph alloc] initWithFbClientID:client_id];
      [fbGraph authenticateUserWithCallbackObject:self andSelector:@selector(fbGraphCallback:) 
                         andExtendedPermissions:@"user_photos,user_videos,publish_stream,offline_access,user_checkins,friends_checkins,user_birthday"];
    
    }
    

    STEP_2

     -(void)post_wall{
    
    
       FbGraphResponse *fb_graph_response = [fbGraph doGraphGet:@"me/feed" withGetVars:nil];
        SBJSON *parser = [[SBJSON alloc] init];
        NSMutableDictionary *parsed_json = [parser objectWithString:fb_graph_response.htmlResponse error:nil];
    
         NSString *get_string = [NSString stringWithFormat:@"%@/picture", [parsed_json objectForKey:@"id"]];
        FbGraphResponse *fb_graph_response1 = [fbGraph doGraphGet:get_string withGetVars:nil];
    NSLog(@"getMeimagePressed:  %@", fb_graph_response1.imageResponse);
        [parsed_json setObject:fb_graph_response1.imageResponse forKey:@"profileImage"];
    
    
    
      if([parsed_json count]>0)
         {
        profil_obj.userprofile_dic=parsed_json;
    
    
    
        if([[NSUserDefaults standardUserDefaults] boolForKey:@"isLogin"]==NO)
        {
            [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"isLogin"];
            [[NSUserDefaults standardUserDefaults] synchronize];
        }
    
    
    }
    else {
        [parser release];
        UIAlertView *ErrorAlrt = [[UIAlertView alloc]initWithTitle:@"Message" message:@"Please check your internet connection and try again.." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
        [ErrorAlrt show];
        [ErrorAlrt release];
    
    
    }
    
    }
    

    第三步

     - (void)fbGraphCallback:(id)sender {
    
    if ( (fbGraph.accessToken == nil) || ([fbGraph.accessToken length] == 0) ) {
    
    
        UIAlertView *alertView = [[UIAlertView alloc] 
                                  initWithTitle:@"FailMessage" 
                                  message:@"You are Not Login to Facebook." 
                                  delegate:self 
                                  cancelButtonTitle:@"OK" 
                                  otherButtonTitles:nil, 
                                  nil];
        [alertView show];
        [alertView release];
        NSHTTPCookieStorage* cookies = [NSHTTPCookieStorage sharedHTTPCookieStorage];
        for (NSHTTPCookie* cookie in [[NSHTTPCookieStorage sharedHTTPCookieStorage] cookies]) {
            [cookies deleteCookie:cookie];
        }
    
    
    } else {
    
        if([[NSUserDefaults standardUserDefaults] boolForKey:@"isLogin"]==NO)
        {
    
    
            profil_obj=[[UserProfile alloc] initWithNibName:@"UserProfile" bundle:nil];
            [self performSelector:@selector(post_wall)];
            [HUD hide:YES]; 
            [self presentModalViewController:profil_obj animated:YES];
            UIAlertView *alertView = [[UIAlertView alloc] 
                                      initWithTitle:@"SucessMessage" 
                                      message:@"You are Sucessfully Login to Facebook." 
                                      delegate:self 
                                      cancelButtonTitle:@"OK" 
                                      otherButtonTitles:nil, 
                                      nil];
            [alertView show];
            [alertView release];
    
    
        }
        else
        {
    
    
            profil_obj=[[UserProfile alloc] initWithNibName:@"UserProfile" bundle:nil];
            [self performSelector:@selector(post_wall)];
            [self presentModalViewController:profil_obj animated:YES];
            [HUD hide:YES]; 
    
        }
    
    
    
    
            }
    
     }
    

    【讨论】:

      猜你喜欢
      • 2016-04-25
      • 1970-01-01
      • 1970-01-01
      • 2012-05-31
      • 1970-01-01
      • 1970-01-01
      • 2010-12-19
      • 1970-01-01
      • 2013-04-13
      相关资源
      最近更新 更多