用于获取Facebook好友数据的FQL查询

时间:2016-03-08 11:56:16

标签: javascript facebook facebook-javascript-sdk

我想从Facebook获取朋友的所有可访问数据(现在只有名字,生日,性别对我来说已经足够了)。我有用户的应用程序ID,我需要的只是公共数据所以我尝试了一些代码,但我只获得名称和Facebook ID。 请在我的代码中建议我该怎么做?



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 : '155509608142654',
                cookie : true, // enable cookies to allow the server to access
                // the session
                xfbml : true, // parse social plugins on this page
                version : 'v2.5' // use version 2.2
            });
            FB.getLoginStatus(function(response) {
                statusChangeCallback(response);
            });
 
        };
        
        
        
 
        // 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/en_US/sdk.js";
            fjs.parentNode.insertBefore(js, fjs);
        }
        (document, 'script', 'facebook-jssdk'));
        function testAPI() {
            console.log('Welcome!  Fetching your information.... ');
            FB.api( '/me?fields=name,friends{age_range,birthday,gender}', function(response) {
                                console.log(response);
                                document.getElementById('userDetails').innerHTML = 'Thanks for logging in, ' + response.name + ' below are your information!' + '<br><b>Name:</b>' + response.name +'<br><b>frnd:</b>' + response.friendgender + '<br><b>frnd list:</b>' + response.friendlists + '<br><b>Facebook link:</b>' + response.link + '<br><b>Local:</b>'  + response.location  + '<br><b>Facebook Id:</b>' + response.id;
                         
&#13;
&#13;
&#13;

&GT;

1 个答案:

答案 0 :(得分:0)

您只能获取授权您的应用的朋友的数据,并具有所需的权限。出于隐私原因,我们已移除了朋友权限:https://developers.facebook.com/docs/apps/changelog

例如,如果您想要过生日,朋友需要使用user_birthday权限授权您的应用。