3

I use Facebook login with my app. (Facebook iOS SDK version 3.11.1)

I ask for "email" permission:

NSArray *permissions = [NSArray arrayWithObjects: @"basic_info", @"email", nil];

Most of the time, I do get the user's email like that:

NSString *email = [user objectForKey:@"email"];
//user is (NSDictionary<FBGraphUser> *)

Sometimes I just don't. (I can see that the NSDictionary is not including email).

I am using this fix so the app won't terminate when i use email later and its nil:

NSString *email = [user objectForKey:@"email"] ? [user objectForKey:@"email"] : @"NO_EMAIL";

But i need the real mail, so i have to come up with a new solution. I haven't noticed something special with the problematic users. Any ideas what can be the problem?

  • known bug for js SDK according to http://stackoverflow.com/questions/16630972/facebook-graph-api-wont-return-email-address – Michael Shabtai Apr 20 '14 at 16:03
  • possible duplicate of [Register with Facebook sometimes doesn't provide email](http://stackoverflow.com/questions/9347104/register-with-facebook-sometimes-doesnt-provide-email) – Sahil Mittal Apr 21 '14 at 06:20

5 Answers5

5

It appears that its a well known problem... For many reasons, not everyone on Facebook have Email address registered.

But as i said, my problem is that i need a real mail. So the simplest solution is to use the user's Facebook Email : user_name@facebook.com

NSString *email = [user objectForKey:@"email"] ? [user objectForKey:@"email"] : [NSString stringWithFormat:@"%@@facebook.com", user.username];
  • some links ref to that you can't sent HTML emails to the Facebook mail, only plain text!
1

Here is how i have done it and it always works great for me in every situation: (I suppose that you have added email permission in your code)

Step 1

Open Facebook Framework folder in Xcode and find the FBGraphUser.h class

As you see, you have there all the properties that you use from Facebook Framework, to take the user details, so add an other property there (copy and paste the code below):

Step 2

 @property (retain, nonatomic) id<FBGraphUser> email;

And you are good to go!

Community
  • 1
  • 1
  • Good to go?? where ??? have you read my question? **I need a real email address**. Adding the property will prevent errors that can occur if the NSDictionary won't have an email in it. **BUT** it won't help me figure if the user has an email address associated with the Facebook account or he doesn't and i have to mail him to the Facebook email (username@facebook.com). – Michael Shabtai Apr 26 '14 at 15:14
0

You could check for a couple of things:

  1. Make sure you are requesting email scope permission in the login request dialog:

    https://www.facebook.com/dialog/oauth?client_id=APP&redirect_uri=REDIRECT&state=UNIQUE&scope=email

  2. Check if the access token you got actually has email permission granted with the Access Token Debugger.

Pablo Santa Cruz
  • 176,835
  • 32
  • 241
  • 292
  • As i wrote, only some users have this problem. I am asking for the email permission (1.) and the access token has the permission according to the Access Token Debugger (2.) – Michael Shabtai Apr 20 '14 at 14:38
0

All facebook accounts which are verified through Phone Number instead of email will get NULL for [user objectForKey:@"email"]

AsifHabib
  • 944
  • 9
  • 25
0

Facebook won't return the email address if it's not verified.

https://developers.facebook.com/docs/graph-api/reference/v2.2/user

This person's primary email address listed on their profile. This field will not be returned if no valid email address is available.

Cristian Pena
  • 2,139
  • 1
  • 19
  • 31