Facebook JS SDK's FB.api('/me') method doesn't return the fields i expect in Graph API v2.4+

后端 未结 4 2123
有刺的猬
有刺的猬 2020-11-21 05:38

I\'m trying to get some basic information using Facebook api, but so far I only get the user\'s name and id. As in { name: \"Juan Fuentes\", id: \"123456\" }

4条回答
  •  爱一瞬间的悲伤
    2020-11-21 06:33

    Here is the complete Script:

    jQuery(document).ready(function () {
        openLoginPopup();
    })
    function openLoginPopup() {
        FB.getLoginStatus(function (response) {
            if (response.status == 'connected') {
                getCurrentUserInfo(response);
            } else {
                FB.login(function (response) {
                    if (response.authResponse) {
                        getCurrentUserInfo(response);
                    } else {
                        console.log('Auth cancelled.');
                    }
                }, {scope: 'email'});
            }
        });
    
    }
    
    function getCurrentUserInfo() {
        FB.api('/me?fields=id,email,first_name,last_name,name', function (userInfo) {
            console.log(userInfo.name + ': ' + userInfo.email);
        });
    }
    
    window.fbAsyncInit = function () {
        FB.init({
    //        appId: 'xxxxxxxxxxxxxxxxxxxxx', //livemode
            appId: 'xxxxxxxxxxxx', //testmode
            cookie: true, // Enable cookies to allow the server to access the session.
            xfbml: true, // Parse social plugins on this webpage.
            version: 'v4.0'           // Use this Graph API version for this call.
        });
    };
    
    
    (function (d, s, id) {                      // Load the SDK asynchronously
        var js, fjs = d.getElementsByTagName(s)[0];
        if (d.getElementById(id))
            return;
        js = d.createElement(s);
        js.id = id;
        js.src = "https://connect.facebook.net/en_US/sdk.js";
        fjs.parentNode.insertBefore(js, fjs);
    }(document, 'script', 'facebook-jssdk'));
    

    Thanks.

提交回复
热议问题