58

For some users in our application, the email field returns NULL even if the user has granted the email access to the app. When we check the scope parameter and the validity of the user Token thanks to the Debugger tool, everything is ok. The permission email has been accepted. But when we ask the Graph API for the email of the user with the valid user token, it does not appear at all.

Is there a way a user could prevent an app from getting his email even if he granted the email permission?

Thanks

Benjamin Naïm
  • 583
  • 1
  • 4
  • 4
  • For PHP Sdk, this [link](http://stackoverflow.com/questions/25069816/facebook-email-field-return-null-even-if-the-email-permission-is-set-and-acce/36332882#36332882) may help some one! – Muhammad Shahzad Mar 31 '16 at 12:05
  • Make sure that the OAuth call you got the access token with include `scope: ['email']`. Make sure to try your acess token with the [Graph API Explorer](https://developers.facebook.com/tools/explorer/) and make sure that the "email" permission on the left is *not greyed out*. – a paid nerd Dec 02 '17 at 20:58

14 Answers14

102

I had the same problem and I think I found out why: If the user has an unconfirmed email in Facebook (i.e. Facebook sent him a validation mail to the user's email address but he didn't respond) Facebook WILL NOT pass that email to your app even if he gave you the email permissions.

So what I did is use his or her Facebook email if the user has a user name (i.e. userName@facebook.com).

gdoron
  • 147,333
  • 58
  • 291
  • 367
ozba
  • 6,522
  • 4
  • 33
  • 40
  • 8
    I have just confirmed this issue. Even after explicitly asking for the user email, Facebook won't give this info to you application until the user confirm his email. Thank you for your answer. I was chasing this for quite a while. – Diogo Melo Dec 15 '13 at 19:07
  • 1
    You welcome, if only @Benjamin Naïm would mark my answer as correct... :) – ozba Dec 21 '13 at 15:11
  • Unconfirmed email also block's the facebook image on response? – Oswaldo Ferreira Jan 29 '14 at 13:30
  • This does make sense, since otherwise people could spam other people's email addresses by setting them as their email address and then signing up for a bunch of things through Facebook. – Glenn Maynard Mar 28 '14 at 22:06
  • 19
    @GlennMaynard even so, Facebook should document it somewhere and not let developers bang their heads trying to figure out why no email is received. – ozba Apr 17 '14 at 08:19
  • @ozba Facebook documents it at https://developers.facebook.com/docs/reference/api/user/ and clarifies some possible reasons for not returning email at https://developers.facebook.com/bugs/298946933534016 – link0ff Aug 18 '14 at 09:29
  • What about if there is no username or email? – Ben Mar 05 '15 at 16:06
  • Thanks a lot! This's been driving me nuts all day long. – Lev Sep 03 '15 at 14:11
  • 5
    But users can change the username if they want. So, there is no point of saving username@facebook.com which varies if the user changes the email. Instead it is better to use uid@facebook.com which is always unique for a particular user. – gwthm.in Aug 22 '16 at 08:26
  • Perhaps, this is answer is wrong. Even I had this issue. Couldn't fix yet it. Still looking for an answer. I went to check this issue, but in my case my email address was verified in the fb account. Even though, I didn't receive email address from that account. – Visal Varghese Feb 01 '17 at 08:02
  • @ozba What happens if we have to send a email to user's email ID (one which we have virtually created)? In this case this solution will fail :( – Shashank Kapsime Feb 22 '18 at 12:12
  • 3
    So i guess everyone has forgotten the fact that user can sign up using his/her mobile number only where email isn't compulsory for signup i believe, and obviously Facebook won't provide mobile number. Facebook profile still works without primary email contact. – Amit Tumkur Oct 22 '18 at 07:42
11

I have the same issue. It is working fine on my localhost, i am using php SDK for facebook login and when i submit my request it's return all the fields like email,name etc of the user but on server somehow it is not working.It will not returns user email. I have done lots of R&D on that and i have the solution for the issue. :)

$profile = $facebook->api('/me?fields=email,first_name,last_name');

if you are using php-sdk just passes fields like this it returns the email,first_name etc. Hopes it works for you all. thanks.

Govinda P
  • 3,261
  • 5
  • 22
  • 43
user3020691
  • 206
  • 2
  • 3
9

All you need to know:

1) Link 1

Some possible reasons:

No Email address on account

No confirmed email address on account

No verified email address on account

User entered a security checkpoint which required them to reconfirm their email address and they have not yet done so

  • Users's email address is unreachable

  • You also need the 'email' extended permission, even for users who have a valid, confirmed, reachable email address on file.

2) Link 2

Note, even if you request the email permission it is not guaranteed you will get an email address. For example, if someone signed up for Facebook with a phone number instead of an email address, the email field may be empty.

hbk
  • 10,908
  • 11
  • 91
  • 124
8

Facebook does not send the email if the user has logged in with their phone number. View the comments on https://github.com/mkdynamic/omniauth-facebook/issues/61 for more info.

user2468170
  • 1,234
  • 2
  • 15
  • 19
3

You must give email permission along with the auth button.

authButton.setReadPermissions(Arrays.asList("email"));
varghesekutty
  • 997
  • 2
  • 11
  • 23
2

In some cases Facebook may not have a valid email address for a user:

email: string containing a valid RFC822 email address - note: this field may be null if no email address is available for the user

see https://developers.facebook.com/docs/reference/api/user/

J Starr
  • 984
  • 6
  • 19
2

@ozba solution is not applicable because facebook now shows an alert message when user has an unconfirmed email address. So, if you're having this problem it's more liking that the user had signed up using phone number. Message when trying to access email

Some possible reasons:

  • No Email address on account (only phone number)
  • No confirmed email address on account
  • User entered a security checkpoint which required them to reconfirm their email address and they have not yet done so users's email address is unreachable.

Check: https://developers.facebook.com/bugs/298946933534016

Priyanshu Chauhan
  • 5,297
  • 5
  • 35
  • 34
2

According to the documentation:

Note, even if you request the email permission it is not guaranteed you will get an email address. For example, if someone signed up for Facebook with a phone number instead of an email address, the email field may be empty.

That would explain why some users have a null email!

d-_-b
  • 21,536
  • 40
  • 150
  • 256
1

Facebook will provide you a user's email id if and only that user has a confirmed email id associated with his account. If your app can retrieve email id for some users, problem may not with the Developer.

1

I have read previous responses but though some of them true like if the user has not email confirmed but a mobile phone number, many times this error happens for ignoring how to request the information using FB api graph. Let's say your login was successfully done, and you now have an access token and user id an so on but still, cannot see email and other fields you are interested in. Go ahead using this request after confirming login status as connected:

FB.api(
  '/me',
  'GET',
  {"fields":"id,name,birthday,email,about,cover"},
  function(response) {
      // Insert your code here
  }
);

depends on permissions you requested you now will be able to catch further information according to your needs.

willyMon
  • 612
  • 8
  • 19
0

you can try this it will work String email = user.getProperty("email").toString(); String safeEmail = user.asMap().get("email").toString();

Hari Haran
  • 1,543
  • 4
  • 13
  • 25
0

You need one more permission from facebook.

include (about_me) permission to the facebook dev setting and also in your app or code..

Prasanna Anbazhagan
  • 1,693
  • 1
  • 20
  • 37
0

Just you need to add more permissions to whatever data you want from Facebook object about your user.

enter image description here

Facebook API

Glorfindel
  • 21,988
  • 13
  • 81
  • 109
Hussam Adil
  • 502
  • 7
  • 13
-1
$loginUrl = $facebook->getLoginUrl(
  array(
    'req_perms' => 'email'
  )
);
armatita
  • 12,825
  • 8
  • 48
  • 49