2014-12-13 84 views
0

我試圖根據性別來分列我的朋友列表,但我不知道如何從他們的id中獲得朋友性別並按性別列出朋友。目前我有他們的id和個人資料照片列出。基本上我需要的只是如何獲得他們的性別並對朋友進行分類。Facebook圖api,得到朋友的性別

 for friend in friends 
    .col-xs-3.col-md-2 
    p #{friend.id} 
    a.thumbnail(href='http://facebook.com/#{friend.id}') 
     img(src='https://graph.facebook.com/#{friend.id}/picture?width=150&height=150') 





exports.getFacebook = function(req, res, next) { 
var token = _.find(req.user.tokens, { kind: 'facebook' }); 
graph.setAccessToken(token.accessToken); 
async.parallel({ 
getMe: function(done) { 
    graph.get(req.user.facebook, function(err, me) { 
    done(err, me); 
    }); 
}, 
getMyFriends: function(done) { 
    graph.get(req.user.facebook + '/friends', function(err, friends) { 
    done(err, friends.data); 
    }); 
} 
}, 
function(err, results) { 
if (err) return next(err); 
res.render('api/facebook', { 
    title: 'Facebook API', 
    me: results.getMe, 
    friends: results.getMyFriends 
}); 
}); 
}; 

回答

0

在您getMyFriends函數調用API來graph.facebook.com/me/friends?fields=name,gender

在響應中的每個項目將看起來像

{ 
     "name": "phwd", 
     "gender": "male", 
     "id": "113702895386410" 
} 

從那裏,你可以打破它。

你也可以做,當然/FRIEND_ID?fields=name,gender

這些電話將不得不與接入附加令牌或通過SDK調用返回。