我正在开发一个需要 Facebook 登录的 ios 应用程序。我已经成功实现了登录过程。但现在我无法找到如何以及在哪里可以获得用户的个人资料信息,如名字、姓氏、个人资料图片等。 ..我的应用程序有权访问名字、姓氏、个人资料图片和电子邮件。
以下是使用最新 Facebook SDK v4.0.1 获取人员 public_profile 的代码。您需要使用 FBSDKProfile 来获取个人资料。
-(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{
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)