Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Facebook not always returning email for user? #61

Closed
swrobel opened this issue Jun 18, 2012 · 131 comments
Closed

Facebook not always returning email for user? #61

swrobel opened this issue Jun 18, 2012 · 131 comments

Comments

@swrobel
Copy link

swrobel commented Jun 18, 2012

I've looked all over the Facebook docs and can't seem to figure out why, even if I require the email permission, I still sometimes get users who are authorized, but do not have email included in the extra hash. Does anyone have any clue how this is possible and how I can absolutely require an email from Facebook?

@steverandy
Copy link
Contributor

I saw this happening for the last couple of days. Sometimes first_name is also blank.

@mkdynamic
Copy link
Collaborator

Odd. If it's intermittent, perhaps it is a FB api issue. Does it happen consistently for all users? Could you show me the config you're using?

@swrobel
Copy link
Author

swrobel commented Jun 27, 2012

Not passing any options other than client_id and client_secret (although using a proc for that because I host multiple domains). Permissions are omniauth-facebook default (I think just email now that offline_access is deprecated). It seems to happen sporadically ... can't figure out exactly what causes it. Is there perhaps a user setting that allows them to not send any email address?

@dpmccabe
Copy link

I'm seeing this problem, too, although it's on a new app and I've never successfully retried the email field. I even tried setting my own email address to be publicly available and I'm requesting it in my provider scope.

@mkdynamic
Copy link
Collaborator

@dpmccabe Does it consistently omit the email? Or is it intermittent?

@swrobel
Copy link
Author

swrobel commented Aug 8, 2012

Looks like this is potentially a platform issue:
Graph API not returning email field even with email permission
API call to /me is missing user's email even with email permission
FQL returning empty email even with email permission granted

Submit your repros so Facebook pays attention!

@dpmccabe
Copy link

dpmccabe commented Sep 5, 2012

I figured out why I've never been able to get the email address. I've been using the JS version of the authorization dialog with the standard page/touch version as a fallback if JS isn't available. You need to specify your permissions scope in the Javascript call to FB.login as described here (under "Permissions"). Merely doing so in the OmniAuth::Builder initializer won't work if you're using the JS SDK.

@swrobel
Copy link
Author

swrobel commented Sep 5, 2012

Unfortunately that isn't my issue since I use the oauth redirect flow and not the js dialog, and I explicitly request the email permission. Still perplexed by this one.

@borama
Copy link

borama commented Nov 23, 2012

I experience the same problem, currently in cca 2% of user registrations. I also don't use the JS dialog login, only the oauth flow.

@oshchyhol
Copy link

Hi. Oauth flow, no js dialog, same issue detected.

@DylanFM
Copy link

DylanFM commented Dec 3, 2012

Just saw this for the 1st time a few days back. Facebook returned a large integer in the email field.

@phuongnd08
Copy link

Me too. Just have 100 fb user so far but 2 of them giving null email, 1 of them giving a large integer number as email field.

@requnix
Copy link

requnix commented Dec 14, 2012

We're also getting this. Can't say what percentage of users have this happen as e-mail is a required field for us and e-mail being missing would cause user creation to fail.

@pramodtech
Copy link

I'm facing same issue but with Twitter, facebook works fine!

@brennanpayne
Copy link

I just had the same issue as phuongnd08, a large int was passed into the email field.

@joeljackson
Copy link

Bump. Are we certain this is on the facebook side of things?

@phuongnd08
Copy link

I'm of doubt, but developer in other language (PHP) also encountered this issue so the high possibility is yes. My workaround is to render a form where user enter their proper email if the returning value is improper (which is an integer in this case).

@jfensign
Copy link

I have just run into this issue too when testing my application on Heroku. The field is returned as one would, or has come to, expect when I am running locally, but is either omitted or returned with a value of undefined on Heroku which leads me to believe this is an issue with their platform.

@matteomelani
Copy link

+1. I also see this bug once in a while. Impossible to reproduce....it just happens once in a while.

@alexis
Copy link

alexis commented Apr 10, 2013

Same issues with facebook: required email permission, but having users without email from time to time. Frustrating :(

@ilandimnik
Copy link

Same issue here. It sometimes resolved after several hours. But it doesn't help for users who registered during that time....

@edlebert
Copy link

I was just hit with this. What the heck is going on?

@swrobel
Copy link
Author

swrobel commented May 23, 2013

Facebook seems to be marking all of the bugs reporting this behavior as duplicates of this bug that they marked back in Feb, but we need to let them know it is NOT fixed!

@alepee
Copy link

alepee commented Jul 16, 2013

Same here for about 2% of users over 12k

@TeamRainless
Copy link

It's actually quite simple (and I can't believe nobody's figured this out yet... was the first thing I thought of.) Some users have supplied a phone number which facebook uses as it's main authentication method instead of the email address. It's really that simple. I believe the phone number is then encrypted and that becomes what the email address would normally be. (Hence no email address in omniauth facebook.) A simple solution to this is to simply have the user supply an email when oauth doesn't: https://github.com/fertapric/rails3-mongoid-devise-omniauth/wiki/How-To:-Retrieve-email-information-%28middle-step%29-from-providers-like-Twitter-or-LinkedIn

@WarrEagle
Copy link

Same issue is occuring with our Node.js/Express/Passport implementation. Fortunately it is not affecting our app, however we cannot contact the user that does have an email address on record.

@alepee
Copy link

alepee commented Aug 7, 2013

The only way I found to prevent it, is to compose an email based on [username]@facebook.com

@WarrEagle
Copy link

That might work...however I think those type of messages are placed into the 'other' message location which the user is not even alerted to..unless you are their friend.

@mayooresan
Copy link

@alepee Thats a gr8 idea. Will do it. 👍

@Maxwell2022
Copy link

Good idea but I'm not sure username is a required information for the user. does it work with: [facebook_id]@facebook.com ?

@ahmedawad250
Copy link

You should add email to scope or add to facebook api get data
api('/me?fields=name,email')

@WarrEagle
Copy link

^ That is not helpful. If a user has their settings set to not supply their email you will get either a null address or an address like 34132142412342@facebook.com if they have messenger enabled.

You just have to detect and/or drop the missing address or @facebook.com address, then force the user to supply a valid email if you require it.

@dfloresgonz
Copy link

dfloresgonz commented Apr 8, 2017

@TeamRainless is right!!! if the user has its phone number set email is not returned I have tested with two accounts one with the phone set and the other one is not, the first one doesn't retrieve the email but the 2nd account does. I guess there is nothing else to do right?

UPDATE:
It's weird another 3rd account has the phone set but it was able to get the email ._. what's going on? could it be the unverified email? how can I tell if the email if unverified?

@aanjna
Copy link

aanjna commented Apr 10, 2017 via email

@steedems
Copy link

I had two identical Facebook apps: one was returning the email and the other was not (same user).

after 3 beers i started trying random stuff, and this one did the trick
screen shot 2017-04-12 at 17 38 10

reset Client Token

@dfloresgonz hope it helps

@jaiswarvipin
Copy link

One of the my friend was trying to the issue from last 5 days. huummm very irritating. which got love in 2 min...

Assumption: using PHP for O2Authentication
Solution:

$loginURL = $fb->getLoginUrl({your redirect URL},['email']);

And job is done.

Thanks & Regards
Jaiswar Vipin Kumar R.

@RicardoRamirezR
Copy link

That worked for me @shahidaali Thank you so much!

@RasoolMohamed27
Copy link

Still am also facing this issue... Please let me know if anyone know to how to fix it...

@cozzbie
Copy link

cozzbie commented Jun 8, 2017

Ran into this and the only thing that worked was requesting for permitted fields through the APIFB.api("/me", {fields: "email,..."}, callback)

@YeWin
Copy link

YeWin commented Aug 17, 2017

@shahidaali Thank you so much!
That worked for me even with old PHP file_get_contents() method.

workaround:
$access_token = json_decode($access_token, true);
file_get_contents('https://graph.facebook.com/me?locale=en_US&fields=name,email,first_name,last_name&access_token=' . $access_token['access_token']);

@statico
Copy link

statico commented Dec 2, 2017

FWIW, I was trying to debug something similar and found that I was sending the scope parameter at the wrong time: jaredhanson/passport-facebook#214 (comment)

@0xjoaovpsantos
Copy link

Today I was running some tests and I came across the same situation, the user's email was not being returned.

Then I realized that Facebook has an option that allows the user to "hide" his or her email, leaving it private, and when the user does it, it is not possible to get the email.

@TeamRainless
Copy link

TeamRainless commented Jan 6, 2018 via email

@nandotuc17
Copy link

Se o email vier nulo basta usar o id_do_usuario@facebook.com já ajuda em algo pelo menos.

@nandotuc17
Copy link

nandotuc17 commented Feb 12, 2018

Também percebi que se eu solicitasse o perfil publico + email via string array no xml não funcionava, vinha apenas o perfil publico, como o perfil publico já vem por padrao eu retirei as permissões do xml e inseri diretamente no código da classe java só o email.

LoginManager.getInstance().logInWithReadPermissions(MainActivity.this,Arrays.asList("email"));

E funcionou perfeitamente.

@RevealedFrom
Copy link

@steedems No joy for me. I have the same situation, two identical apps, one returns email but one won't.

@simi
Copy link
Owner

simi commented May 10, 2018

@RevealedFrom for the same user asking for the same permissions?

@RevealedFrom
Copy link

@simi Yes, testing with the same Facebook user account. Exact same Express app with passport-facebook, and just switching client id and client secrets to test with different Facebook apps. So far, the score is 2 will return emails, and 1 will not.

@simi
Copy link
Owner

simi commented May 10, 2018

Are there any differences between facebook apps configurations?

@RevealedFrom
Copy link

RevealedFrom commented May 11, 2018

Went through page by page, couldn't find any material differences. Anyway, it says email is always approved by default. I wonder what other settings could have prevented email from being sent.

From the user side, going to www.facebook.com/settings?tab=applications shows that two apps have the choice of email but one doesn't.

@samarulrajt
Copy link

For me this code worked charm to fetch user info and email.
FB.api('/me?fields=name,email,first_name,last_name,id', function(response) { console.log(response); }, {scope: 'public_profile,email'});

@feliperaul
Copy link

feliperaul commented Jul 4, 2018

I'm now clocking at around 6 hours of debugging, without any luck. Before e-mail was being retrieved, now it isn't. Created test users on Application Dashboard, and nothing. Created a new app for testing only, nothing. The info hash comes with name and image only, no matter what I pass on scope and info_fields.

This is the latest code I'm running, but I've tried more then 50 variations of all these parameters. Giving up for the week.

Rails.application.config.middleware.use OmniAuth::Builder do

  provider(:facebook,
    Rails.application.secrets.facebook_app_id,
    Rails.application.secrets.facebook_app_secret,
    scope: 'email,public_profile',
    info_fields: 'name,email',
    display: 'popup',
    callback_path: "/tourists/auth/facebook/callback",
    token_params: { parse: :json },
    client_options: { site: "https://graph.facebook.com/v3.0", authorize_url: "https://www.facebook.com/v3.0/dialog/oauth" }
  )

end

@feliperaul
Copy link

@shahidaali could you please take a look?

@feliperaul
Copy link

My current workaround - terrible, but only way I managed to get an e-mail addres - was using Koala gem, initializing an instance with the request.env['omniauth.auth'].credentials.token token and then requesting the e-mail address using the token:

@graph = Koala::Facebook::API.new(request.env['omniauth.auth'].credentials.token) profile = @graph.get_object("me", fields: ['email'])`

@mariothedev
Copy link

mariothedev commented Sep 19, 2018

After over-reading all comments and becoming increasingly frustrated, I found a quick solution:

https://graph.facebook.com/v3.1/me?fields=id%2Cname%2C%20email%2C%20picture&access_token=YOURTOKENHERE

&

passport.authenticate('facebook', {
scope: ['email']
}),

@sushant12
Copy link

thanks @codevanaco , adding it to the scopes did the trick

@gsolak
Copy link

gsolak commented Sep 23, 2019

https://graph.facebook.com/me?fields=email,first_name,last_name&access_token={token}

By default, the email field will not return unless specified.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests