Need help.
how to get facebook email on sign in using php sdk
Search for "Declarative Fields" in the changelog: https://developers.facebook.com/docs/apps/changelog#v2_4
You have to specify the fields you want to get, else you will only get ID and name. For example:
/me?fields=name,email
Include java script FB SDK:
<script>(function(d, s, id) { var js, fjs = d.getElementsByTagName(s)[0]; if (d.getElementById(id)) return; js = d.createElement(s); js.id = id; js.src = "http://connect.facebook.net/en_US/all.js#xfbml=1&appId=PLACE_YOUR_FB_APP_ID"; fjs.parentNode.insertBefore(js, fjs); }(document, 'script', 'facebook-jssdk'));</script>
Initiate link to connect with Facebook:
<script>function FBLogin(){
FB.login(function(response){
if(response.authResponse){
var USERID = response.authResponse.userID;
FB.api('/me', function(userinfo){
jQuery.ajax({
type:"POST",
url: "ajax_fb_login.php",
data: "userinfo="+userinfo,
success: function(html){
}
});
});
}
}, {scope: 'email,user_likes'});
}</script>
Retrieve the facebook data in your php file:
$fbid = $_REQUEST['userinfo']['id']; $email = $_REQUEST['userinfo']['email']; $first_name = $_REQUEST['userinfo']['first_name']; $last_name = $_REQUEST['userinfo']['last_name']; $fb_name = $_REQUEST['userinfo']['name'];