Facebook chart does not return email address

UPDATE It seems that my personal email address has not been used for years. Facebook noted that it is inactive and does not return it as part of JSON.

I test the 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 get the code, which I then change to a token:

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

Then I send the token to my server, and I get the Fb schedule to get user information, including email.

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

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

What have I done wrong?

+8
javascript facebook facebook-graph-api
source share
1 answer

According to the documentation for Facebook :

By default, not all fields in a node or edge are returned when you make a request. You can select the fields (or edges) that you want to return with the "fields" query parameter. It is really useful for making your API more efficient and faster.

This is true from v2.4 (previous versions extracted some fields by default).

When registering a new application, you have the right automatically (without manual viewing) to three permissions: email, public_profile and user_friends. In your code, "email" is in scope (which is good), so just change your request to:

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

You probably need the public_profile fields that you automatically received in previous versions of the API. Do 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 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.

+5
source share

All Articles