how to get email id of Facebook user using javascript sdk

前端 未结 6 1098
后悔当初
后悔当初 2020-12-08 04:34

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 Facebo

6条回答
  •  情歌与酒
    2020-12-08 05:14

    In this code i have get user data form facebook and store into my database using ajax

     FB.login(function(response) {
              if (response.authResponse) {
             FB.api('/me?fields=email,name,first_name,last_name', function(response) 
             {
                 FB.api(
                 "/"+response.id+"/picture?height=100",
                                        function (responses) {
                                            //console.log(responses.data.url)
                                                        response['profile_pic']=responses.data.url;
                                            $.ajax({
                                                       type:"POST",
                                                       url:''+'home/facebook_get_signup',
                                                       data:response,
                                                       success:function(res)
                                                       {
                                                           if(res=='success')
                                                           {
    
                                                               window.location='';
                                                           }
                                                           if(res=='exists')
                                                           {
                                                               window.location='';  
                                                           }
                                                       }
                                                   });
    
                                        }
                                    )
             });
            } else {
             console.log('User cancelled login or did not fully authorize.');
            } 
          // handle the response
            }, {scope: 'email,user_likes'});
    

提交回复
热议问题