I am using Facebook Javascript SDK to get oauth token and retrieve all the data from FB:
function login() { FB.api('/me', function (response) { alert('You have successfully logged in, ' + response.name + ", " + response.email + "!"); });
I retrieve all basic information (full name, work, school, ID..) but not EMAIL (response.email == undefined) !!
I know it's possible to access email within basic information (not asking for 'email' permissions), how do I do that?
The simplest way to get a copy of the User Profile object is to access the /me endpoint: FB. api('/me', function(response) { }); This will this will return the users name and an ID by default.
OAuth is also used when giving third-party apps access to accounts like your Twitter, Facebook, Google, or Microsoft accounts. It allows these third-party apps access to parts of your account. However, they never get your account password.
You need get email explicitly as follows:
var url = '/me?fields=name,email'; FB.api(url, function (response) { alert(response.name); alert(response.email); });
And to get the email address, email permission is needed. So the code might look like (there are other options like Register button, login button..)
FB.login(function (response) { if (response.session) { var url = '/me?fields=name,email'; FB.api(url, function (response) { alert(response.name); alert(response.email); }); } else { alert("User did not login successfully"); } }, { scope: 'email' }); /* perms changed to scope */
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With