[Facebook-iOS-SDK 4.0] How to get user email address from FBSDKProfile

I am updating my application to Facebook-iOS-SDK-4.0 , but it seems that I can not receive email from the user FBSDKProfile , since it provides only the username, user, etc.

+45
objective-c facebook-ios-sdk
Mar 28 '15 at 10:14
source share
8 answers

To receive e-mail, you need to use the chart API, in particular, specify the parameter field filled with the fields you need. Take a look at the Graph Graph API API tool to help you find answers to your queries. https://developers.facebook.com/tools/explorer

The code that worked for me to receive email is as follows: it is assumed that you are already logged in:

  NSMutableDictionary* parameters = [NSMutableDictionary dictionary]; [parameters setValue:@"id,name,email" forKey:@"fields"]; [[[FBSDKGraphRequest alloc] initWithGraphPath:@"me" parameters:parameters] startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) { aHandler(result, error); }]; 
+128
Jul 14 '15 at 13:54 on
source share

It is right. The email address is not in the FBSDKProfile object. You should use the FB Graph API instead. The FB Developer website has a lot of information and code examples https://developers.facebook.com/docs/ios/graph.

To answer your question, try something like this.

 if ([FBSDKAccessToken currentAccessToken]) { [[[FBSDKGraphRequest alloc] initWithGraphPath:@"me" parameters:@{@"fields": @"email"}] startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) { if (!error) { NSLog(@"user:%@", result); } }]; } 
+28
Mar 29 '15 at 1:45
source share

Adjusted Code:

  if ([FBSDKAccessToken currentAccessToken]) { [[[FBSDKGraphRequest alloc] initWithGraphPath:@"me" parameters:nil] startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) { if (!error) { NSLog(@"fetched user:%@", result); } }]; } 
+6
Apr 27 '15 at 13:13
source share

Try this code:

 FBSDKLoginManager *login = [[FBSDKLoginManager alloc] init]; [login logInWithReadPermissions:@[@"email"] handler:^(FBSDKLoginManagerLoginResult *result, NSError *error) { if (error) { // Process error } else if (result.isCancelled) { // Handle cancellations } else { // If you ask for multiple permissions at once, you // should check if specific permissions missing if ([result.grantedPermissions containsObject:@"email"]) { if ([FBSDKAccessToken currentAccessToken]) { [[[FBSDKGraphRequest alloc] initWithGraphPath:@"me" parameters:nil] startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) { if (!error) { NSLog(@"fetched user:%@", result); } }]; } } } }]; 
+4
May 30 '15 at 11:04
source share

These options gives the email address

 NSDictionary *parameters = @{@"fields":@"email"}; [[[FBSDKGraphRequest alloc] initWithGraphPath:@"me" parameters:parameters] startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) { NSLog(@"fetched user:%@", result); }]; 

starting with Graph API v2.4, GET requests for / me must contain an explicit parameter "fields"

+3
Jan 04 '16 at 8:54 on
source share

From the facebook developer site https://developers.facebook.com/docs/facebook-login/permissions/v2.2

Please note that even if you request an email permission, it is not guaranteed you will receive an email address. For example, if someone signed up with Facebook with a phone number instead of an email address, the email address field may be blank.

Hope this helps someone :)

+2
Nov 15 '15 at 12:36
source share

I wanted to add what I found to this. For my FBSDKGraphRequest I tried to transfer the permissions that I requested at login as fields. So I installed fields somehow like:

"email,user_location"

However, permissions and fields are different. For reference, these are the fields: https://developers.facebook.com/docs/graph-api/reference/v2.4/user

So based on this link you want to pass:

"email,location"

Hope this helps someone!

+1
Aug 23 '15 at 18:26
source share
 if ([FBSDKAccessToken currentAccessToken]) { [[[FBSDKGraphRequest alloc] initWithGraphPath:@"me" parameters:@{@"fields": @"email"}] startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) { if (!error) { } }]; } 
0
Apr 17 '19 at 6:24
source share



All Articles