Facebook Login

5

I have a code with which I make a login through Facebook, and it is as follows:

<script>
    window.fbAsyncInit = function() {
        FB.init({
        appId      : 'xxxxxxxxxxxxxxxx',
        xfbml      : true,
         version    : 'v2.6'
        });
    };

    (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 = "//connect.facebook.net/en_US/sdk.js";
        fjs.parentNode.insertBefore(js, fjs);
    }(document, 'script', 'facebook-jssdk'));

    function validarUsuario() {  
        FB.getLoginStatus(function(response) {  
            if(response.status == 'connected') {  
                FB.api('/me', function(response){  
                    alert('Hola ' + response.name);  
                });  
            } else if(response.status == 'not_authorized') {  
                    alert('Debes autorizar la app!');  
            } else {  
                alert('Debes ingresar a tu cuenta de Facebook!');  
            }  
        });  
    }  

    function ingresar() {  
        FB.login(function(response){  
            validarUsuario();  
        }, {scope: 'public_profile, email'});  
    }
</script>

And the call to the function "enter" I do it with the following button:

<div id="IngresaFacebook" onclick="ingresar()"></div>

My question is this:

I have no idea how to get the scope data. I could only get the name with "response.name", but I do not know how to get the email. Could someone help me with this? Thanks!

    
asked by Criss 23.05.2016 в 02:53
source

1 answer

1
FB.api('/me?fields=id,name,email,permissions', function(response) {
    console.log('Me alegro de verte, ' + response.email + '.');
    alert('Me alegro de verte, ' + response.email + '.');
});  
  

Allows access to the main email address of the person through the email property of the user object.

     

...

     

Please note that requesting the email permission does not guarantee that you obtain an email address. For example, if a user signs in to Facebook with a phone number instead of an email address, this field may be empty.

Reference - Facebook for developers

    
answered by 23.05.2016 / 03:19
source