Reputation: 115
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?
Upvotes: 3
Views: 2453
Reputation: 2249
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.
Upvotes: 0
Reputation: 950
All facebook accounts which are verified through Phone Number instead of email will get NULL
for [user objectForKey:@"email"]
Upvotes: 0
Reputation: 400
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!
Upvotes: 1
Reputation: 115
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 : [email protected]
NSString *email = [user objectForKey:@"email"] ? [user objectForKey:@"email"] : [NSString stringWithFormat:@"%@@facebook.com", user.username];
Upvotes: 5
Reputation: 181280
You could check for a couple of things:
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
Check if the access token you got actually has email permission granted with the Access Token Debugger.
Upvotes: 0