1

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!

Community
  • 1
  • 1
adiego73
  • 189
  • 1
  • 3
  • 13
  • Did you try using curl or wget on your graph url, and not just using the graph api explorer? It might be worth checking out the raw api response to see if its consistently missing an email, or if something else is wrong. – Nick DeFazio Jul 08 '13 at 16:27
  • Hi! We try using curl, and the response have the email field.. Also, we realize that after 2 or 3 retries we get the right response (with the email). I´ve dried up all of my options :( – adiego73 Jul 08 '13 at 18:42
  • Do you get inconsistency in curl as well? Did you try it more than once? Just trying to rule out an API related issue before considering restclient. I found this post on github(https://github.com/mkdynamic/omniauth-facebook/issues/61) and it seems others were having issues with this as well, and its somewhat recent. It wouldn't be the first time the FB Graph API wasn't totally consistent :) – Nick DeFazio Jul 08 '13 at 18:54
  • We've tried almost 5 times until the access token expired and the responses were always OK. We are getting rid on this with an asyc call until we get the right response of facebook. If the response is always the same, we assume that the user have no email. – adiego73 Jul 08 '13 at 19:32
  • Possible duplicate of [Intermittent missing email address in facebook API](https://stackoverflow.com/questions/7603644/intermittent-missing-email-address-in-facebook-api) – Paul Sweatte Jul 10 '17 at 18:44

0 Answers0