65

Edit: Not Duplicate, because:

  • I have the permission
  • Debugged the token
  • Code works with test user

Please don't mark as duplicate without reading.

I'm trying to get the user e-mail address, but i don't get it. On graph api explorer, when i hit send, email field becomes grayed and says that:

field is empty or disallowed by access token

But when I debug the token it has email permission granted

My profile has an e-mail address.

Update: I tried https://developers.facebook.com/tools/console/ . My profile returns nothing, even on another computer. But the same code returns the email, name and uid of another account.

Code:

    <fb:login-button scope="email">
  Grant Permissions to make more examples work
</fb:login-button>

<button onclick="doPost()">Post to Stream</button>

<script>
function userData() {
  FB.api('/me?fields=name,email', Log.info.bind('/me callback'));
};

FB.getLoginStatus(function(response) {
  if (response.status === 'connected') {
    userData();
  }
});
</script>

It is possible to lockdown you e-mail so no one can has it? Even when i grant permission?

Tomasz Kowalczyk
  • 10,472
  • 6
  • 52
  • 68
Maxinne
  • 1,693
  • 2
  • 23
  • 47
  • 1
    @karthikr, nope, scope added, permission granted (Debug shows that the token has email permission), but no email... I can get another data, just email won't come. Just to clear, i'm using javascript sdk and using Graph API Explorer. – Maxinne May 19 '13 at 05:24
  • 1
    Have you found a solution to this? I'm having the same problem and it's driving me nuts! – Mihai Fratu Sep 04 '13 at 13:07
  • 1
    @MihaiFratu, no... I tried everything i found, and the situation is very inconsistent, with some users (like test ones you can setup) working and live ones from some friends with valid primary e-mail addresses that wont. – Maxinne Sep 04 '13 at 16:57
  • Filled bug: https://developers.facebook.com/bugs/340561996079829 – Maxinne Sep 26 '13 at 20:22
  • I haven't tried this anymore but from what the response on your bug report says I get that you didn't confirmed your email address? Try doing that, maybe it will help. – Mihai Fratu Sep 28 '13 at 23:55
  • One thing that I have noticed is that this happens when the user that you are using is also admin of the FB app...I don't know why. – almo Jul 23 '17 at 01:17

6 Answers6

44

The Marcus' answer leads me to the real problem I was facing.

Debugging with the Facebook Explorer tool I was able to figure out that I should set the email scope at the FB.api() method after a successful login.

FB.login(function(response) {
    if (response.status === 'connected'){
        FB.api('/me?fields=id,email,name', function(data) {
        console.log( data.email ) // it will not be null ;)
    })
}, {scope: 'email'});

It is not quite clear at the Quickstart guide and I hope it helps someone else, too.

Youp Bernoulli
  • 5,303
  • 5
  • 39
  • 59
Miere
  • 1,495
  • 2
  • 19
  • 24
36

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 his 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 Facebook email if he has a user name (i.e. userName@facebook.com).

ozba
  • 6,522
  • 4
  • 33
  • 40
  • Thats a good work around... The only problem with it is that if you try to send some mailing or other sort of e-mail communication, it will go to the "Other" inbox on facebook. – Maxinne Dec 15 '13 at 17:59
  • And if my answer suffice for you please mark it as so, thank you :) – ozba Dec 17 '13 at 14:59
  • 1
    @ozba facebook emails can be disabled and I know many people having that disabled for spamming reasons. Also there is no way of getting the username any longer from the Graph API. So you shouldn't rely on the Facebook email. –  Jan 08 '16 at 08:16
21

After i got my bug report marked as duplicate, and i read all posts and links there, i got what caused this problem for me and how to fix.

The Problem Facebook seems to sometimes forget what your primary e-mail is on the graph API (But it still there in the preferences.)

Solution The user affected must remove the e-mail, save settings, then re-add the address, re-confirm, then make it primary. This fixed my account both on my sandbox app, and other apps where Facebook login don't used to work.

Maxinne
  • 1,693
  • 2
  • 23
  • 47
  • Another solution is just to add another email address to your account and the original email address now becomes primary – dannrob Jul 15 '14 at 13:30
  • How is that a solution? It just means we loose the customer, we can't even tell him why because we don't have his email. – shredding Oct 01 '20 at 13:45
  • @shredding, it *is not* a solution, it is a problem on Facebook side... What you can do is check if you got the e-mail, and if not, ask for it from the user... – Maxinne Oct 02 '20 at 00:23
8

New facebook graph requires scopes added in the /me request as follow:

/me?fields=email,birthday,location,locale,age_range,currency,first_name,last_name,name_format,gender&access_token=

Alin Razvan
  • 1,451
  • 13
  • 18
4

I had the same issue while I was developing the fb login button for my site. I had even setup permissions for my app here:

https://developers.facebook.com/apps/<my-app-ID>/permissions

and it was working fine for certain initial cases, that is, it was giving email (i tested it on my own account and it was giving my email). Then suddenly it started to reflect no email at all. After two hours of browsing, I figured it out that there was an issue with the access token as when I went on this link:

https://developers.facebook.com/tools/explorer/<your-fb-id>/?method=GET&path=100002451127858%3Ffields%3Did%2Cemail

Update your-fb-id with your id and go to the above link. Click on 'Get Access Token'. In the tab that opens up, click on 'Extended Permissions' and in that, choose 'email' and submit. Now, test your query again. It'll definitely work, on the console as well as your website. Cheers! :)

Sayed
  • 601
  • 6
  • 21
  • Thank You It works for me (Note: You will find Get User Access Token Option and then from list select email) – Abhi Burk Aug 29 '18 at 19:27
2

This is a known bug. If the user does not have any email address set to primary, the query will return null for email. Set the email address for your account to primary https://www.facebook.com/settings?tab=account&section=email&view and then try.

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

spence0021
  • 61
  • 1
  • 6