Facebook Graph /me missing email - facebook

We have issues with our web app and Facebook.
I'm doing the Login with scope email
FB.login(function(response) {
// my code
}, {scope: 'email', auth_type: 'rerequest', return_scopes: true});
I got the popup asking permission for the email, and other fields
I accept it, but then after getting the access_token, I call
https://graph.facebook.com/v15.0/me?fields=id,first_name,last_name,name,email,picture.type(large)&access_token={MY_TOKEN}
The email field is not in the response
What I don't understand is that user is a test user created on Facebook app page. One in Two users I create have this issue. For some other users, I have the email with the same exact procedure
Do you know what could happen?

We are experiencing the same issue.
WizKid is right. Try using https://developers.facebook.com/tools/explorer/ and you'll see that when you get no email, this tool shows "The email field was not returned. This may be because the email was missing, invalid or hasn't been confirmed." message.

Related

Why is the Facebook login modal not prompting users for access to their email address?

I'm trying to integrate the Facebook login flow into a website (as per this page: https://developers.facebook.com/docs/facebook-login/web), and I'm having issues with trying to force the login modal to request access to the user's Facebook email address.
Specifically, I'm executing the following code from my JS:
FB.login((response) => {
if (response.status === 'connected' &&
response.authResponse) {
// Do something with the response here.
}
}, {
scope: 'email',
return_scopes: true
});
The response is coming back as connected when the user successfully logs in, and I am getting the user's user ID, access token, etc., but when they click on the button in my UI that calls FB.login, the modal that pops up for Facebook does not ask the user if they want to grant access to their email address. Why?
For the site I'm building, I need access to the user's Facebook email address. If they were to be asked and deny access, that's one thing, but the modal that pops up isn't even asking them for access to their email address, and I don't get their email address back in the response.
Furthermore, if I make a subsequent call to the following, the email permission comes back as declined:
FB.api(`/${response.authResponse.userID}/permissions`, (response) => {
console.log(response);
});
Does anyone know why I can't prompt the user for access to their email address? Thanks.
Edit: It might be worth mentioning that I'm testing this on localhost, and I wonder if that's having an effect. In the Facebook for Developers dashboard, I did set my localhost virtual host (e.g., site-name.test) as an allowed URL for redirects, and it does let me log in with Facebook and get the user ID, etc., but it just never prompts the user for access to their email address. Thanks.
Thanks again to misorude for the answer. Without that, I would have never figured this out. To sum everything up, the problem was that during testing, I had apparently already once declined the request to provide access to my email address, and after that, it no longer asked me for permission to access it.
As such, you have to pass an extra parameter to FB.login in order to force it to re-ask the user for access to their email address. Specifically, it's the authType parameter, and here's how you pass it:
FB.login((response) => {
if (response.status === 'connected' &&
response.authResponse) {
// Do something with the response here.
}
}, {
scope: 'email',
authType: 'rerequest'
});
That will give you access to the email address (assuming a user has one registered; again, thanks to misorude for noting that), but it doesn't actually return the email address. To get that, you then have to send an API request to /me with a fields parameter requesting the email address to get it. I figured out how to get that via the following SO answer: https://stackoverflow.com/a/31763373/1992973
Specifically, a full solution is something like the following:
FB.login((response) => {
if (response.status === 'connected' &&
response.authResponse) {
FB.api('/me?fields=email', (response) => {
// The email should be in the response, assuming the user has one registered with FB.
});
}
}, {
scope: 'email',
authType: 'rerequest'
});

Facebook Graph API not return email and id properly (06/01/2018)

i'm using graph api FB.init with
config:
cookie : true, xfbml : true, version : 'v2.11'
prmision:
email,user_hometown,user_religion_politics,publish_actions,user_likes,user_status,user_about_me,user_location,user_tagged_places,user_birthday,user_photos,user_videos,user_education_history,user_posts,user_website,user_friends,user_relationship_details,user_work_history,user_games_activity,user_relationships
FB.api("/me/taggable_friends?fields=id,name,email&limit=100", function(response){
if(response && !response.error){
console.log(response);
}
});
But the outpus just like this:
MyOutputGraphAPI
why id and email did not show up properly
Please help me.
taggable_friends is for tagging only, so you just get the name and a tagging token. You can only get the email of a user if that user authorized your App. You cannot get the email of friends if they did not authorize your App.
The API call: /me/friends?fields=id,name,email
Again, this only returns emails of friends who authorized your App with the email permission. There is no other way to get emails, you would not even be allowed to store the emails without the permission of each single user anyway.

Facebook UI, how to check if a user can send facebook message to another user

I want to follow up this question. I use FB.ui to send link and got exactly the same error for some users. Is there anyway to check it and decide whether to display the ui to the user ?
API Error Code: 100
API Error Description: Invalid parameter
Error Message: Viewer cannot message specified recipients.
<a href='#' onClick="
FB.ui({
method: 'send',
link: 'http://www.xxxxxxxxxxx.com',
to: ###########,
});
">Send a message</a>
Even when I use the url send method, some user does not work. For example:
Error User : https://www.facebook.com/dialog/send?app_id=123050457758183&name=People%20Argue%20Just%20to%20Win&link=http://www.nytimes.com/2011/06/15/arts/people-argue-just-to-win-scholars-assert.html&redirect_uri=https://www.bancsabadell.com/cs/Satellite/SabAtl/&to=100000104626944
Normal User: https://www.facebook.com/dialog/send?app_id=123050457758183&name=People%20Argue%20Just%20to%20Win&link=http://www.nytimes.com/2011/06/15/arts/people-argue-just-to-win-scholars-assert.html&redirect_uri=https://www.bancsabadell.com/cs/Satellite/SabAtl/&to=1311251197
(this is the share link example taken from https://developers.facebook.com/docs/reference/dialogs/send/)
bug reported to facebook: https://developers.facebook.com/bugs/538638372825668
Edit: in fact, everyone should be reachable through messages now. It's only there are new "filtering preferences". I guess this can_message field is now useless because it should always return true. I think it is going to be deprecated in a while.
In the user FQL table, you have a field that must verify what you need:
can_message (boolean): whether the user can send a message to another user
Source: https://developers.facebook.com/docs/reference/fql/user
select can_message from user where uid=USER_ID
USER_ID being the person that your app user want to send a message to.
You can use the FB api;
I use something like:
FB.api('/me/permissions', function (response)
{
//check contents of response for required permissions here
fb_publish_perm = response.data[0]['publish_stream'] ? response.data[0]['publish_stream'] : false;
if (fb_publish_perm)
{
// it permissions exist
}
else
{
// permissions dont exist launch the ui to request.
}
});
Please treat the above as psedo code, as it came straight off the top of my head!

Unsupported scope "proxied email" - Facebook SDK

I want to get the emails of my friends using FQL, so I pass the permission "proxied_email" to Facebook SDK. It shows error on FB dialog:
"Invalid parameter. Error message: Unsupported scrop: "proxied_email".
I think this is a bug
Apparently this link says that I need the permission "proxied_email"
Is it a bug???
By the way, I can't get the email, it always returns null. How to do it?
proxied_email is not a permission, but a field in the User FQL table. This is why you get an error.
You must ask for the email permission to get the email.
Here is how to get the email:
SELECT email FROM user WHERE uid=USER_ID

posting reply to inbox message?

I'm trying to post a reply to an inbox message by sending a POST request to /message_id/comments. Is this the correct way to send a reply to an inbox message ?
I'm getting the following error:
"error": {
"type": "OAuthException",
"message": "(#3) App must be on whitelist"
}
The token has every possible permission.
Do I have to ask that my app is added on a whitelist ? how to do so ?
I'm doing this in javascript+jQuery:
var params = {
access_token: token
, method: 'post'
, message: 'hi'
};
$.getJSON('https://graph.facebook.com/$message_id/comments?callback=?', params, function(json) {
});
Facebook apps by default aren't allowed to send messages on behalf of users. There is no permission you are missing. This is an extra level to prevent spam (beyond prompting the user who). You will have to contact Facebook to get your application whitelisted. I would try their developer group.
opened a support ticket right here:
http://developers.facebook.com/bugs/183144141763793?browse=search_4e8b140cbf26e6040457329
Tried all I can think of and googled for, still getting this issue
Like others have pointed out, there isn't a way to do this programmatically unless you are on Facebook's whitelist. However, I did find a way around this for my app. What I do is use Oauth to display messages from a user's FB inbox like normal. When the user clicks 'Reply' on a message, I just send them to the reply page on Facebook Mobile, like this:
$('.reply').click(function() {
var popup_window = window.open('http://touch.facebook.com/messages/compose?ids='+message_id, '_blank');
popup_window.focus();
});
Where message id is the Facebook id for the message they are replying to. In my case, I use PHP to echo the message id into a javascript variable or data-attribute when the page loads. Since the Facebook mobile page opens in a new tab, they don't even really leave my app. Since Facebook mobile has a very streamlined interface it isn't too distracting. It's not perfect, but it works and it's easier than trying to get whitelisted.