K
K
Kirill Gorelov2017-12-14 00:44:24
PHP
Kirill Gorelov, 2017-12-14 00:44:24

facebook registration?

Guys, you need to register on the site through facebook. I do everything as in the documentation.
And I have a problem. If the user is registered through the computer, then everything is fine. And if from a mobile phone, then facebook does not give all the fields, that is, the email is empty, and on it, in fact, everything is tied up with us.
Here is my code. And I don’t understand what’s wrong with nm, I did it as in the documentation.

<script>
function handle_fb_data(response){
        FB.api('/me?fields=id,email,link,last_name,first_name', function(response) {
            // console.log('Successful login for: ' + response.name);
            console.log(JSON.stringify(response));


            $.ajax({
                type: 'post',
                url: '/ajax/reg_user_fb.php',
                data:response,
                success: function(msg) {
                    console.log(msg);
                    data = JSON.parse(msg);
                    if (data.rez=='true'){
                    		window.location.reload();
                    	}
                },
                error: function(){}
            })

        });
    }

    function fb_login(){
        FB.getLoginStatus(function(response) {
            if (response.authResponse) {
                // console.log('Welcome!  Fetching your information.... ');
                handle_fb_data(response);
            } else {
                FB.login(function(response){
                    if (response.authResponse) {
                        // console.log('Welcome!  Fetching your information.... ');
                        handle_fb_data(response);
                    } else {
                    }
                });
            }
        }, {
            scope: 'email,id,link,last_name,first_name'
        });
    }

    window.fbAsyncInit = function() {
        FB.init({
            appId      : 'idприложения',
            cookie     : true,  // enable cookies to allow the server to access
            // the session
            xfbml      : true,  // parse social plugins on this page
            version    : 'v2.11' // use graph api version 2.8
        });
    };
    // Load the SDK asynchronously
    (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/ru_RU/sdk.js";
        fjs.parentNode.insertBefore(js, fjs);
    }(document, 'script', 'facebook-jssdk'))

</script>

//кнопка
<a class="social-login-fb soc_facebook" onclick="fb_login();" href="javascript:void(0)"></a>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
Philipp, 2017-12-14
@zoonman

1. Scope is incorrect. https://developers.facebook.com/docs/facebook-logi...
2. If a user registers from a phone, then he most likely does not have an email.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question