Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to get email id of Facebook user using javascript sdk

I am using JavaScript API to create my app for Facebook. The problem is, it's returning
email = undefined.

I don't know why? And if I use Facebook login/logout button on my app then the alert shows correct email id of the user but I don't want to do that. What am I missing?

Here is my code:

<p><fb:login-button autologoutlink="true" perms="user_about_me,email"></fb:login-button></p>  <script> window.fbAsyncInit = function () {   FB.init({ appId: '250180631699888', status: true, cookie: true,   xfbml: true });    FB.getLoginStatus(function (response) {     if (response.session) {       greet();     }   }); }; (function () {   var e = document.createElement('script');   e.type = 'text/javascript';   e.src = document.location.protocol +   '//connect.facebook.net/en_US/all.js';   e.async = true;   document.getElementById('fb-root').appendChild(e); } ());  function greet() {   FB.api('/me', function (response) {   alert('Welcome, ' + response.name + "!");   alert('Your email id is : '+ response.email); }); } </script> 
like image 656
user958414 Avatar asked Oct 19 '11 11:10

user958414


People also ask

What is Facebook SDK for JavaScript?

The Facebook SDK for JavaScript provides a rich set of client-side functionality that: Enables you to use the Like Button and other Social Plugins on your site. Enables you to use Facebook Login to lower the barrier for people to sign up on your site. Makes it easy to call into Facebook's Graph API.


1 Answers

// https://developers.facebook.com/docs/javascript/reference/FB.api/ // v2.4  FB.api('/me', { locale: 'en_US', fields: 'name, email' },   function(response) {     console.log(response.email);   } ); 
like image 127
masakielastic Avatar answered Sep 28 '22 23:09

masakielastic