Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Facebook Graph not returning email

UPDATE It seems that my personnal email address had not been used for years. Facebook marked it as inactive and did not return it as part of the JSON.

I am authenticating a user with Facebook on the client side using this url :

https://www.facebook.com/dialog/oauth?
  client_id=xxx&
  redirect_uri=https://www.facebook.com/connect/login_success.html&
  scope=email

I receive a code I then exchange for a token :

https://graph.facebook.com/oauth/access_token?
  code=xxx&
  client_id=xxx&
  client_secret=xxx&
  redirect_uri=xxx

I then send the token to my server and I fetch the Fb Graph in order to get some user info, including the email.

 https://graph.facebook.com/me?access_token=xxx

For some reason, I get all the user 'about' info, but not his/her email!

What did I do wrong?

like image 589
Justin D. Avatar asked Aug 22 '13 18:08

Justin D.


1 Answers

According to the Facebook Documentation:

By default, not all the fields in a node or edge are returned when you make a query. You can choose the fields (or edges) you want returned with the "fields" query parameter. This is really useful for making your API calls more efficient and fast.

This is valid from v2.4, (previous versions retrieved some default fields).

When you register a new app you are entitled automatically (without manual review) to three permissions: email, public_profile and user_friends. In your code "email" is in scope (which is good) so just change your query to:

https://graph.facebook.com/me?access_token=xxx&fields=email

You probably wanted the public_profile fields that you automatically got in previous versions of the API. Do so so, add "public_profile" to your scope:

https://www.facebook.com/dialog/oauth?
  client_id=xxx&
  redirect_uri=https://www.facebook.com/connect/login_success.html&
  scope=email,public_profile

And now add the user name fields to your query:

https://graph.facebook.com/me?access_token=xxx&fields=first_name,last_name,gender,email,timezone,age_range,verified

Good luck

like image 174
PalDev Avatar answered Oct 14 '22 04:10

PalDev