Facebook Callback JSON does not return email sometimes - facebook

Facebook Graph API.
I am requesting email permission and it works all fine except for some users, the json does not return email field. I am not sure why this happens. The code is same and it works great for all users, returns email field except 1 in 100 or so users where it does not have this field in json. All other fields are there.
Has anyone faced this problem before ??
I checked the facebook privacy settings and there is nothing that prevents email from coming in json if user grants email access to facebook app, yet this is happening to me. I searched the net and no one else seems to be facing this issue.
Any hint would be appreciated

Never makes assumptions about what Facebook will send you, never expect every field to be present and never expect a Graph request to do what you want.
Facebook sometimes do things like this, a missing field here and there, a cryptic and unexpected error somewhere else… While it can be no harm be aware that it also happens in critial places like in the signed_request sent when an user launches an app.
You also have to know that 'your' Facebook may not be everyone else's Facebook. They do geographic and somewhat random deployments of their code. An option to hide your e-mail address to every application could appear for someone but not for someone else, without any particular reason.
Considering your particular issue, I doubt there is an option to hide you e-mail address to an app who has the mail permission, but if the permission is not mandatory someone could accept your app and cherry-pick optional permissions later.

I dealing with this issue recently. Apparently, facebook only promise to return "valid email" address. Some account do not having any "valid email". They can be account who using phone for validation, or account that email is expired. I tried with a account which email, lets said "xxxx.gmail.com" is expired, when query that account graph, i unable to get any email shows(by using facebook debugger). However, when i login xxxx.gmail.com in gmail, and re-activate the email, and i query graph api again for the account, it able to return me email.

had the same issue for a while, which caused some heavy head banging against the wall.
in my case the issue was due to the fact that some users have unverified emails or no email at all (when signing up via mobile/SMS).
in this case facebook will not provide an email on the response.
from the facebook docs:
note: this field will not be returned if no valid email address is
available for the user
sources:
https://github.com/mkdynamic/omniauth-facebook/issues/61
Register with Facebook sometimes doesn't provide email (sebastian's and colm's answers)
https://developers.facebook.com/docs/reference/api/user/

The only thing that worked for me was requesting for permitted fields through the API:
FB.api("/me", {fields: "email,..."}, callback)
This totally fixed the issue.
Hope that helps.

Related

How can I get owner email for a Facebook App using the App Access Token

How would I get the email address associated with an active Facebook App ID, if all the usual methods (such as here, and here) don't return any email information with my creator-uid?
(I simply don't get the email field returned, even when I specifically request it as per here. I don't think this is a case of this as I didn't get an "App has no owner" error, or any error whatsoever.)
I've also tried this, but I'm in a catch-22 as I can't log in to select the application first.
I'm looking for the owner email address, so I can log in to make administrative updates following graph API updates.
Other specifics:
I get the following when I hit the Graph API via: https://graph.facebook.com/{my-app-id}?access_token={my-access-token} or https://graph.facebook.com/{my-app-id}?access_token={my-access-token}&fields=email
{
"name": "my-name",
"id": "my-creator-uid" }
I've tried to recover my FB account using all emails I can think of, but FB says 'no account exists' for each that I try. (This is a data-analytics corporate account being used to gather data for 12+ months, so I can't simply create a new account/app ID and start using that instead, as app-scoped user IDs will change.)
I've also tried viewing https://www.facebook.com/app_scoped_user_id/{my-creator-uid}/ and https://www.facebook.com/{my-creator-uid}/ from another company FB account, but both get:
Sorry, this content isn't available right now The link you followed
may have expired, or the page may only be visible to an audience
you're not in.
What else would you suggest? What might have happened? I've tried to contact Facebook, but that search led me to this forum post, so I'm here. Thank you in advance for your help.
This is not a programming question, try to get in touch with the Facebook Team, if you are working with Facebook paid services (like Advertising) you might have an account representative that can accelerate the things a little bit (But this can be a really long wait).
A more realistic option is to create a new profile and an new app, also your application will be reviewed as well (Take a little less time than previous option).

Email extended permission not granted in some cases

I am using the server-side authentication flow, and when requesting the email extended permission, once in a blue moon the email address is not sent back, causing my application to break.
That information is required for my application to function properly, so I will modify it to re-prompt the user. But I would like to understand why/how this happens since I cannot find any way to revoke that permission from the application when authorizing. The dialog states that the permission is required. Is this because of accounts belonging to minors that can't give out that information?
I'm requesting like so: https://www.facebook.com/dialog/oauth/?client_id=$appId&redirect_uri=$fbAuthUrl&state=$stateString&scope=email
It's possible that some users simply won't have an email - Earlier, it was possible to sign up for Facebook with a cell phone only - I'm not sure if there's some other reason or, it could be a bug with the API
After much head banging, I found this bug filed with Facebook that I think is responsible:
https://developers.facebook.com/bugs/487563591260030

Is it possible to determine the #Facebook.com email address of a user?

Is it possible to figure out reliably what the Facebook email of any Facebook user would be? I know earlier this was not possible because not all users had a username. But I believe that has changed since...
I'm trying to figure out a way to let a user send a direct message to their friend through my app. The Request feature is pretty messed up now as you cannot send a custom message, which means most friends are probably going to ignore the request.
The type of messages that I am trying to let my users send to their friends would not be considered spam by Facebook, as these are messages sent directly from the user to their friend, except it is done through the app. But it's pointless if the message just says "Joe wants you to try this app..." The usefulness of an app on the Facebook platform is becoming questionable now.
I think that facebook terms and conditions disallow this...
Facebook messaging (i.e., email sent to an #facebook.com address) is designed for communication between users, and not a channel for applications to communicate directly with users."
Despite your caveat at the end of your post I believe that facebook would consider this a message from your app to the user.
In terms of your question, then the user data returned includes 'username' which is the information you need to create the email address.
Is it possible to figure out reliably what the Facebook email of any Facebook user would be? I know earlier this was not possible because not all users had a username. But I believe that has changed since...
Yes, now every user should have a username set – if not by themselves, than FB will have chosen one for them.
Besides that, I think writing to userid#facebook also works.
But I agree with combinatorial’s answer – Facebook explicitly says that this should not be used for app-to-user communication. To judge if your case is OK is up to you – otherwise you might consider using the send dialog instead, that’s more of the “designated” way to have users communicate “through” your app.
If what you are looking for is to give them a new message notification, it is not going to work. Because, if you send an email to the facebook email, it will land in the Others folder in the message box, which is like a spam box.Try mailing your own #facebook id and see what happens.
And Facebook doesnt give any documentation of how to get users #facebook email, most probably because they dont want developers to use it.
Why dont you mail them directly? You can easily get their email by adding email to the scope, and you can catch the email easily too.
$data = file_get_contents("https://graph.facebook.com/me?access_token=xxxxxx");
$data = json_decode($data,true);
$email = $data['email'];
Is that a viable option in your case?

Facebook Graph API returning numbers instead of email addresses

I'm using Facebook Connect along with the Facebook Graph API to fetch user's email addresses when they sign up to my site. This works perfectly over 99% of the time but sometimes when I query the Graph API for a user's data after they have given my site permission, including the email permission, Facebook returns a large number (eg. 14036774009) as the person's email address.
So far, the numbers are always different and are always 11 digits long and all the other user data from the Graph API is valid. I've never been able to replicate this problem with a Facebook account that I control.
In some ways, the large number reminds me of the random proxy email addresses that Facebook generates for people who opt to give 3rd party apps a forwarding address instead of their main address (the proxy addresses look something like this: apps+148742679521093.617890126.8a2b26037e1ccd06bb81aaec5925f4c7#proxymail.facebook.com)
Can anyone explain this behavior or a way to fix it (and always get valid email addresses)?
It's a bug. Has already been reported to Facebook:
https://developers.facebook.com/bugs/298946933534016
It seems to be happening even when using the graph explorer - https://developers.facebook.com/tools/explorer, but only for some users. In my case about 0.2% of the time.
So until it is fixed you have 2 options:
If Facebook gives you a bad email value, ask the user for his/her email manually.
Save the long lived access token and try again periodically to see if you get the correct email back.
Are you still using the old auth dialog somehow?
The ability to provide a proxy email address is only in the old auth dialog
This happens for people who sign up to Facebook with their mobile phone number and the number returned is just that.
There is no option to get at the users' email address because he may not have given it to Facebook yet.

Graph API incorrectly returning empty array

I'm trying to run a simple query on the graph api. I just want to pull back the id of a user based on the email address they use to login to facebook.
I am using the following query:
https://graph.facebook.com/search?q=facebook.xxx#xxx.xid.au&type=user&access_token=AAADxxxxT64Q8BADcpCdWBojPXPLbZBsSjzj8LPUPhyYJMGWaRuZAP56wIR4BaiUZAaPZA22Ex2y7bgBQHTxxxxxxxxxxxx
and am getting the following in response (no errors, no data)
{
"data": [
]
}
I know the email address is valid - it is my own. This query had worked fine in the past. Any tips on where I should look to for debugging?
https://graph.facebook.com/search?q=facebook.xxx#xxx.xid.au&type=user
Due to privacy concerns searching by email address has been disabled.
However, if you have a user who has granted you email permissions, you can get their email address, however you are limited as to what you can use that email address for.
EDIT
It was filed as a bug (https://developers.facebook.com/bugs/292220680814266) and now is resolved.
Looks like Facebook has caved in to peer pressure and is now allowing this search to happen again.
I think you have no permission to access user's data.
see https://developers.facebook.com/docs/reference/api/permissions/ for more details