如何在ios 9中使用facebook sdk 4.7获取用户的电子邮件ID

这里是我的代码,我只获取用户的用户名和Facebook的ID。

FBSDKLoginManager *login = [[FBSDKLoginManager alloc] init]; [login logInWithReadPermissions: @[@"public_profile",@"email",@"user_friends"] fromViewController:self handler:^(FBSDKLoginManagerLoginResult *result, NSError *error) { if (error) { NSLog(@"Process error"); } else if (result.isCancelled) { NSLog(@"Cancelled"); } else { if ([FBSDKAccessToken currentAccessToken]) { [[[FBSDKGraphRequest alloc] initWithGraphPath:@"me" parameters:nil] startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) { if (!error) { NSLog(@"fetched user:%@", result); } }]; } NSLog(@"Results=%@",result); NSLog(@"Logged in"); } }]; 

它也给这样的错误 –

-canOpenURL:URL失败:“fbauth2:/” – 错误:“(null)”-canOpenURL:URL失败:“fbauth2:/” – 错误:“(null)”

FBSDKLog:从Graph API v2.4开始,/ us的GET请求应该包含显式的“fields”参数

我使用Facebook SDK的pod,它在iOS9.0 xcode 7.1的工作。 试试这个代码

  void (^sendRequestsBlock)(void) = ^{ FBSDKGraphRequest *postRequest = nil; NSDictionary *parameters = [NSDictionary dictionaryWithObject:@"id,email,first_name,last_name,name,picture{url}" forKey:@"fields"]; postRequest = [[FBSDKGraphRequest alloc] initWithGraphPath:@"me" parameters:parameters HTTPMethod:@"GET"]; [postRequest startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) { if (!error) { NSDictionary *dictResult = (NSDictionary *)result; } }]; }; /// login start FBSDKLoginManager *login = [[FBSDKLoginManager alloc] init]; [login logOut]; NSArray *permissions = [NSArray arrayWithObjects:@"email",@"public_profile", nil]; [login logInWithReadPermissions:permissions fromViewController:self handler:^(FBSDKLoginManagerLoginResult *result, NSError *error) { if (error) { } else if (result.isCancelled) { } else { if ([result.grantedPermissions containsObject:@"email"]) { sendRequestsBlock(); } } }]