I'm developing a REST service using Java with Spring, that connects to Facebook and gets some user data like name, last_name, and the most important: email.
The service has a method that expects Facebook uid and the access token, and then it gets the user info by calling to https://graph.facebook.com/me/?fields=email,id,last_name,name&access_token=XXXXX and parsing the json response.
The problem is that some users have no email in the response.. I know that there are facebook users who haven't set an email, because they create their account using a phone number. That's not the problem here.
When I use RestTemplate class, the email is not in the response, but when I use the Graph API Explorer tool (https://developers.facebook.com/tools/explorer/), the email is there.
With RestTemplate:
RestTemplate rest = new RestTemplate();
String jsonResponse = rest.getForObject("https://graph.facebook.com/me/?fields=" + fields + "&access_token=" + accessToken, String.class);
JSONObject o = JSONObject.fromObject(jsonResponse);
Response with RestTemplate:
{
"id": "xxxxxxxx",
"last_name": "Avila",
"name": "Diego Emanuel Avila"
}
Response with Graph API Explorer
{
"id": "xxxxxxxx",
"email": "xxxxxx@gmail.com"
"last_name": "Avila",
"name": "Diego Emanuel Avila"
}
I don't know if the problem is in RestTemplate class, or in Facebook Graph API.. I don't know if I have to add a header or something like that, to get the right response from Facebook.
Looking for an answer here, I stumbled upon with this Intermittent missing email address in facebook API, but it's not the same issue as mine.
I hope I made myself clear and you can help me out with this.
Thanks a lot!