Facebook iOS SDK does not return user email address

I am trying to access user information, including email. For this purpose, I use the Graph API to call this method:

[facebook requestWithGraphPath:@"me" andDelegate:self]; 

It returns information about the user without email (birthday is also missing). I installed all permissions and tested several accounts (which have email and birthday as public information) and accepted all dialogue requests.

Here is my init:

 if(!facebook) { facebook = [[Facebook alloc] initWithAppId:[self _APP_KEY] andDelegate:self]; NSArray *array = [NSArray arrayWithObjects: @"email", @"user_birthday", @"publish_stream", @"offline_access", nil]; [self setPermissions:array]; } NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; if ([defaults objectForKey:@"FBAccessTokenKey"] && [defaults objectForKey:@"FBExpirationDateKey"]) { facebook.accessToken = [defaults objectForKey:@"FBAccessTokenKey"]; facebook.expirationDate = [defaults objectForKey:@"FBExpirationDateKey"]; } if (![facebook isSessionValid]) { [facebook authorize:permissions]; } else { [self getUserInfo]; } 

Login callback:

 - (void)fbDidLogin { NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; [defaults setObject:[facebook accessToken] forKey:@"FBAccessTokenKey"]; [defaults setObject:[facebook expirationDate] forKey:@"FBExpirationDateKey"]; [defaults synchronize]; [self getUserInfo]; } 

GetUserInfo method:

 - (void) getUserInfo { [facebook requestWithGraphPath:@"me" andDelegate:self]; } 

Request callback:

  - (void)request:(FBRequest *)request didLoad:(id)result { if ([result isKindOfClass:[NSDictionary class]]) { NSDictionary* json = result; NSLog(@"-> %@", json); } } 

The result is the following:

 -> { "first_name" = EDITED (my name); gender = male; hometown = { id = 111072692249998; name = "Porto Alegre"; }; id = 653099452; languages = ( { id = 104034306299811; name = "Brazilian Portuguese"; }, { id = 106059522759137; name = English; } ); "last_name" = EDITED (my last name); link = EDITED (my profile); locale = "en_US"; location = { id = 112047398814697; name = "S\U00e3o Paulo, Brazil"; }; name = EDITED (my name); timezone = "-3"; "updated_time" = "2012-04-25T13:36:51+0000"; verified = 1; } 

As you can see, there is no user email information. Am I missing a step? Any ideas?

Thanks in advance

+7
source share
7 answers

Try using this, it works in my case

facebook = [[Facebook alloc] initWithAppId: [self _APP_KEY] and Delegate: self]; [facebook authorize: [NSArray arrayWithObjects: @ "email", nil]];

+7
source

Try this permissions = [[NSArray alloc] initWithObjects: @ "offline_access", @ "email", nil];

+3
source

you can get the user's email address as follows .. after fbDidlogin dismissed the call to this method

 - (void)fetchUserDetails { NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys: @"SELECT uid, name, pic, email FROM user WHERE uid=me()", @"query",nil]; [fb requestWithMethodName:@"fql.query" andParams:params andHttpMethod:@"POST" andDelegate:self]; } 

and in request:(FBRequest *)request didLoad you will do something like this:

 - (void)request:(FBRequest *)request didLoad:(id)result { if([request.url rangeOfString:@"fql.query"].location !=NSNotFound) { if ([result isKindOfClass:[NSArray class]] && [result count]>0) { result = [result objectAtIndex:0]; } if ([result objectForKey:@"email"]) { NSLog(@"%@",[result objectForKey:@"email"]); } } } 

Enjoy :)

+1
source

1) Give permission to receive e-mail and information, etc.

 // You must ALWAYS ask for public_profile permissions when opening a session [FBSession openActiveSessionWithReadPermissions:@[@"public_profile",@"user_videos",@"email"] allowLoginUI:YES completionHandler: ^(FBSession *session, FBSessionState state, NSError *error) { // Retrieve the app delegate AppDelegate* appDelegate = [UIApplication sharedApplication].delegate; // Call the app delegate sessionStateChanged:state:error method to handle session state changes [appDelegate sessionStateChanged:session state:state error:error]; }]; 

2) to get the email where you want ...

 if (FBSession.activeSession.isOpen) { [[FBRequest requestForMe] startWithCompletionHandler: ^(FBRequestConnection *connection, NSDictionary<FBGraphUser> *user, NSError *error) { if (!error) { NSString *userEmail = [user objectForKey:@"email"]; } [tblSettingVw reloadData]; }]; } 

Note. User dictionary will return after

 { "first_name" =; gender =; id =; "last_name" =; link = ""; locale = ""; name = ""; timezone = ""; "updated_time" = ""; verified = ; } 
+1
source

All facebook accounts that are verified using the Phone Number instead of email will receive NULL for [user objectForKey:@"email"]

+1
source

You can only access the user's email if you get user authorization.

The public graph does not provide this information.

You should read the following: https://developers.facebook.com/docs/guides/web/#login

0
source

You need to request this information from the user using:

 - (BOOL)openSessionWithAllowLoginUI:(BOOL)allowLoginUI { NSArray *permissions = [[NSArray alloc] initWithObjects: @"user_birthday", nil]; return [FBSession openActiveSessionWithPermissions:permissions allowLoginUI:allowLoginUI completionHandler:^(FBSession *session, FBSessionState state, NSError *error) { [self sessionStateChanged:session state:state error:error]; }]; 

}

Here is all the information you need, just follow these tutorials

Firstly: Facebook Login

And then, this one: Get user data

0
source

All Articles