0

How can we get user email id using facebook connect? I am trying to get user email id through below code:

 FB.api('/me', function(response) 

But it is not responding user email id and in my application has required email to check validation.

Please assist me.

2 Answers2

0

You cannot get the email address of each and every user on facebook. That is a privacy related issue. The corresponding user may have blocked access from viewing their email.

Your code will work only if the user has enabled others to view their emails.

Try such id and you will get it.

I found this thread on SO, See if it is useful.

Community
  • 1
  • 1
Shankar Narayana Damodaran
  • 68,075
  • 43
  • 96
  • 126
0

The same way you access name. i.e

response.email and response.id

but to fetch email address you must have the permission to access it.

Add scope="email" to your FB Login Button.

function login() {
    FB.login(function(response) {
        if (response.authResponse) {
            // connected
        testAPI();
        } else {
            // cancelled
        }
    }, { scope: 'email' });
    }

function testAPI() {

    console.log('Welcome!  Fetching your information.... ');
    FB.api('/me', function(response) {

        console.log('Good to see you, ' + response.name + '.' + ' Email: ' + response.email + ' Facebook ID: ' + response.id);
    });
}

Here's a good tutorial for beginners: http://www.loginworks.com/technical-blogs/404-working-with-facebook-javascript-sdk

i am not associate with above link to any promotion it is just for information

Also it is a privacy related issue. above code will work only user enabled others to view his/her emails.

liyakat
  • 11,825
  • 2
  • 40
  • 46
  • @Abhishek Anand Patel,i am sure my answer would sure help you.it would be glad for me if you will acept my answer. – liyakat Sep 21 '13 at 09:24