简体   繁体   中英

Problems fetching 'email' from Facebook using javascript sdk api v2.4

I'm using the code that is on the FB Login documentation for Javascript. But it doesn't fetch user's email adresss. It was working with older versions...but it doesnt with the version of my app (v2.4). I'm also using the facebook login button.

Here's what I've got:

function statusChangeCallback(response) {
    console.log('statusChangeCallback');
    console.log(response);

    if (response.status === 'connected') {
        testAPI();
    } else if (response.status === 'not_authorized') {
        document.getElementById('status').innerHTML = 'Please log ' +
            'into this app.';
    } else {
        document.getElementById('status').innerHTML = 'Please log ' +
            'into Facebook.';
    }
}

function checkLoginState() {
    FB.getLoginStatus(function(response) {
        statusChangeCallback(response);
    });
}

window.fbAsyncInit = function() {
    FB.init({
        appId: '1650558335190396',
        cookie: true,
        xfbml: true,
        version: 'v2.4'
    });

    FB.getLoginStatus(function(response) {
        statusChangeCallback(response);
    });

};

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

function testAPI() {
    console.log('Welcome!  Fetching your information.... ');
    FB.api('/me', function(response) {
        console.log('Successful login for: ' + response.name + response.id);
        document.getElementById('status').innerHTML =
            'Thanks for logging in, <br>' + response.name + '<br>' + response.id + '<br> <img src="http://graph.facebook.com/' + response.id + '/picture" /></br>' + response.email;
    });
}

And this is the button part:

<fb:login-button scope="email,user_birthday,user_about_me"   autologoutlink="true" onlogin="checkLoginState();">
</fb:login-button>
FB.api('/me?fields=name,email', function(response) {...

在变更日志中搜索“声明性字段”: https : //developers.facebook.com/docs/apps/changelog#v2_4

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM