简体   繁体   English

iOS获取用户的Facebook ID和朋友列表与朋友的个人资料图片URL

[英]iOS getting User's Facebook ID & friends List with Profile picture URL of Friends

I want to get user id from Facebook and Friend list, with friends id & profile picture URL of friends. 我希望从Facebook和朋友列表中获取用户ID,以及朋友ID和朋友的个人资料图片网址。 I've two code samples, first is 我有两个代码示例,第一个是

NSDictionary *params = @{@"fields": @"name, id, picture"};
FBSDKGraphRequest *request = [[FBSDKGraphRequest alloc] initWithGraphPath:@"/me/friends" parameters:params HTTPMethod:@"GET"];

this returns friend list with profile picture URL of friends too, but does not return user's own Facebook id. 这也返回朋友列表,其中包含朋友的个人资料图片网址,但不会返回用户自己的Facebook ID。 Second is 第二是

[[[FBSDKGraphRequest alloc] initWithGraphPath:@"/me" parameters:@{@"fields": @"id,name,friends, picture"}]

This returns user's Facebook id, friend list but doesn't return profile picture URL of friends. 这返回用户的Facebook ID,朋友列表但不返回朋友的个人资料图片URL。 Can you help me out here, how can I get both things in one call ? 你能帮我解决这个问题,我怎样才能在一次通话中得到这两样东西?

please use below code snippet: 请使用下面的代码片段:

-(void)getFacebookFriednData{

    FBSDKLoginManager *fbSdkLoginManager = [[FBSDKLoginManager alloc] init];
    [fbSdkLoginManager logOut];    
    [fbSdkLoginManager logInWithReadPermissions:@[@"email",@"public_profile",@"user_friends"] fromViewController:self handler:^(FBSDKLoginManagerLoginResult *result, NSError *error) {
        if (!error) {
            if (!result.isCancelled) {
                NSDictionary *params = @{@"fields":@"id,name,email,picture,friends"};
                FBSDKGraphRequest *request = [[FBSDKGraphRequest alloc]
                                              initWithGraphPath:@"me"
                                              parameters:params
                                              HTTPMethod:@"GET"];
                [SVProgressHUD show];
                [request startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
                    [SVProgressHUD dismiss];
                    if (!error) {

                       NSLog(@"%@",result); // here u get all require data              
                    }
                }];
            }
        }else{
            NSLog(@"%@",error.localizedDescription);  ?/ Handle Error Here.
        }
    }];

}

SWIFT 3 SWIFT 3

This is how I get this info for friends who are using my app 这就是我为使用我的应用程序的朋友获取此信息的方式

if ((FBSDKAccessToken.current()) != nil){

    if let request = FBSDKGraphRequest(graphPath: "me/friends", parameters: ["fields": "email, name, gender, picture"] ) {
         request.start(completionHandler: { (connection, result, error) in

             if (error == nil){
                  guard let userInfo = result as? [String: Any] else { return } //handle the error
                  print("data------:\(userInfo)")
             } else {

                  //handle any errors

             }
        }
    }
}

The userInfo has the data you need. userInfo包含您需要的数据。

您可以使用此代码:

NSString *pictureURL = [NSString stringWithFormat:@"https://graph.facebook.com/%@/picture?type=large&return_ssl_resources=1", facebookID];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM