我尝试从登录的 Facebook 用户那里至少获取 id、用户名和电子邮件。我首先使用权限类型登录:电子邮件。如果成功,请尝试获取 FBSDKGraphRequest,它会返回除电子邮件之外的所有可能值。
我也尝试添加诸如 public_profile 之类的权限,但无论如何我尝试,我都没有收到电子邮件。我查看了开发人员仪表板,电子邮件似乎默认被批准。
FBSDKLoginManager *loginManager = [[FBSDKLoginManager alloc] init];
[loginManager logInWithReadPermissions:@[@"email"] fromViewController:self handler:^(FBSDKLoginManagerLoginResult *result, NSError *error) {
if (error) {
NSLog(@"Error: %@", error);
return;
} else if (result.isCancelled) {
return;
}
FBSDKGraphRequest *request = [[FBSDKGraphRequest alloc] initWithGraphPath:@"me" parameters:@{@"fields": @"id, name, gender, first_name, last_name, locale, email"}];
[request startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
if (error) {
NSLog(@"Error: %@", error);
return;
}
NSLog(@"Fetched user: %@", result);
}];
}];