在iOS应用程序中获取某个人的Facebook公开个人资料

问题描述:

我正在使用需要Facebook登录的ios应用程序.我已经成功实现了登录过程.但是现在我无法找到如何以及在何处获取用户的个人资料信息,例如名字,姓氏,个人资料图片等...我的应用有权访问名字,姓氏,个人资料图片和电子邮件.

I am working on an ios app which requires Facebook Login.I have successfully implemented the login process.But now I am not able to find that how and where can i get the user's profile information like first name,last name, Profile Pic etc...My app has permissions to access firstName,lastName,Profile pic and Email.

以下是使用最新的Facebook SDK v4.0.1使人员成为public_profile的代码.您需要使用FBSDKProfile来获取个人资料.

Below is the code for getting person public_profile using latest Facebook SDK v4.0.1. You need to use FBSDKProfile to get person profile.

-(void)viewDidLoad{
        FBSDKLoginButton *loginButton = [[FBSDKLoginButton alloc] init];
        [self.view addSubview:loginButton];

        self.loginButton.readPermissions = @[@"public_profile", @"email", @"user_friends"];
        self.loginButton.delegate = self;
        [FBSDKProfile enableUpdatesOnAccessTokenChange:YES];
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(profileUpdated:) name:FBSDKProfileDidChangeNotification object:nil];

         }

    -(void)profileUpdated:(NSNotification *) notification{
         NSLog(@"User name: %@",[FBSDKProfile currentProfile].name);
         NSLog(@"User ID: %@",[FBSDKProfile currentProfile].userID);
    }

    - (void)  loginButton:(FBSDKLoginButton *)loginButton
    didCompleteWithResult:(FBSDKLoginManagerLoginResult *)result
                    error:(NSError *)error{

    }

    - (void)loginButtonDidLogOut:(FBSDKLoginButton *)loginButton{

    }