Reputation: 1963
I am struggling to retrieve email from Facebook. It is suppose to be simple but I don't know why its not returning. Below is the code.
- (IBAction)loginClicked:(id)sender {
FBSDKLoginManager *login = [[FBSDKLoginManager alloc] init];
[login
logInWithReadPermissions: @[@"email", @"public_profile"]
fromViewController:self
handler:^(FBSDKLoginManagerLoginResult *result, NSError *error) {
if (error) {
NSLog(@"Process error");
} else if (result.isCancelled) {
NSLog(@"Cancelled");
} else {
NSLog(@"Logged in");
[self getUserInfo];
}
}];
}
-(void) getUserInfo {
if ([FBSDKAccessToken currentAccessToken]) {
[[[FBSDKGraphRequest alloc] initWithGraphPath:@"me" parameters:@{@"fields": @"id, name, first_name, last_name, picture.type(large), email"}]
startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
if (!error) {
NSLog(@"fetched user:%@", result);
}
}];
}
}
This is retrieving all other fields except email.
Upvotes: 0
Views: 172
Reputation: 1066
As per the facebook documentation
This field will not be returned if no valid email address is available.
It is possible to sign up for facebook without giving an email address. Mobile numbers can be used instead. There is also a full explanation from one of the facebook engineers at: https://developers.facebook.com/bugs/298946933534016
Upvotes: 3