21

My application uses the "https://graph.facebook.com/me" request with an OAuth token to obtain properties about the user. Email address is one of the properties we need, and we do explicity request that permission when we request access.

It's working fine 99% of the time, but on a few occasions the response comes back without any object in the jSON data named "email".

Is there an explanation as to why this might happen, such as a way a user could grant us permission but still block their email address? Or could it be found under another key?

Thanks.

Frank LaRosa
  • 3,533
  • 6
  • 26
  • 32
  • do you have workaround for this? – JR Galia May 23 '13 at 02:37
  • possibly in addition to what others are saying, Facebook accounts for children either have no email or their email is omitted from this kind of access. for my client, this means they simply aren't allowed to use the app. – changokun Nov 12 '13 at 14:12
  • Unconfirmed email is not sent via API: http://stackoverflow.com/questions/17532476/faceboofk-email-field-return-null-even-if-the-email-permission-is-set-and-acce – Konstantin Fadeyev Dec 23 '13 at 20:53

6 Answers6

11

Short answer: Not all users have an email address available and those who do may not have a valid, reachable email address

The documentation for the email field of the user object ( https://developers.facebook.com/docs/reference/api/user/ ) clarifies the expected behaviour here, which is: "this field will not be returned if no valid email address is available"

There are a number of circumstances in which you may think a user should have an email address returned but they will not. Some common reasons:

  • No Email address on account
  • No confirmed, 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 (which users can choose not to allow), even for users who have a valid, confirmed, reachable email address on file.

Igy
  • 43,710
  • 8
  • 89
  • 115
8

The mobile signup form at http://touch.facebook.com/r.php allows you to signup with an email address or phone number. So I don't think all Facebook users have an email address stored with them.

drewrichards
  • 583
  • 4
  • 7
  • +1, it's also possible for a user to not have a confirmed email address via other methods, such as if their email address is no longer active, or if they haven't confirmed it – Igy Apr 08 '14 at 21:36
3

If you are using facebook SDK 2.4 or higher you need to add "fields" in the strategy

Below is an example for oAuth library.

FacebookStrategy.php line 131

BEFORE:

$me = $this->serverGet('https://graph.facebook.com/me', array('access_token' => $access_token), null, $headers);

AFTER:

$me = $this->serverGet('https://graph.facebook.com/me', array('access_token' => $access_token,'fields'=>'email,name,first_name,last_name,age_range,gender'), null, $headers);

Regardless of the field list, if you want to get more information that is not by default provided by Facebook, the permissions need to be in the "scope" array.

Default data provided by SDK includes: email, public profile, user_friends

Nathan Tuggy
  • 2,237
  • 27
  • 30
  • 38
mate.gvo
  • 1,093
  • 14
  • 20
3

The user can revoke the email address permission on the app privacy settings page without revoking the full application. You could first call /me/permissions to make sure the email permission is still granted.

bkaid
  • 51,465
  • 22
  • 112
  • 128
  • 1
    That makes sense, but I couldn't duplicate the problem. When I access the app privacy settings on my own account, it lists the "Send me email" permission as "Required" and won't let me revoke it. – Frank LaRosa Sep 29 '11 at 22:19
  • I'm having the same issue. I have a user that doesn't return an email when /me is called. I checked /me/permissions and email=1. Is it possible it's a facebook bug or that the user doesn't have an email registered? – Kyle Fleming Oct 01 '11 at 02:20
  • It does seem like a bug. I would log it here: https://developers.facebook.com/bugs – bkaid Oct 01 '11 at 02:23
  • I think this is the same issue: https://developers.facebook.com/bugs/139022569529487 – Kyle Fleming Oct 02 '11 at 01:03
2

Had the same problem and discovered that in the rare cases where this happens the user did not have a primary E-Mail-Address defined (although 2 Addresses were registered). We're not able to reproduce such a costellation, since normally it is not possible not to have a primary e-mail address.

Can anyone confirm something similar?

Martin Schuhfuß
  • 6,814
  • 1
  • 36
  • 44
2

Missing email field happens where user doesn't confirm his primary address via clicking link from activation message.

SkyKnight
  • 21
  • 1