I am using JavaScript API to create my app for Facebook. The problem is, it's returningemail = 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>
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.
// 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); } );
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