繁体   English   中英

使用带有节点的Facebook图形API获取性别和年龄

[英]Get gender and age with facebook graph api with node

我正在尝试通过使用Node.js的Facebook Graph API获取用户的性别和生日。 我的问题是只显示用户的ID和名称,我不知道为什么。

到目前为止,这是我的代码:

Facebook.js

    var https = require('https');

exports.getFbData = function(accessToken, apiPath, callback) {
    var options = {
        host: 'graph.facebook.com',
        port: 443,
        path: apiPath + '?access_token=' + accessToken, //apiPath example: '/me/friends'
        method: 'GET'
    };

    var buffer = ''; //this buffer will be populated with the chunks of the data received from facebook
    var request = https.get(options, function(result){
        result.setEncoding('utf8');

        result.on('data', function(chunk){

            buffer += chunk;
        });

        result.on('end', function(){
            callback(buffer);
        });
    });

    request.on('error', function(e){
        console.log('error from facebook.getFbData: ' + e.message)
    });

    request.end();
}

这就是我所说的:

 facebook.getFbData(access_token, '/me/friends', function(data){

此代码仅返回用户ID和名称,如何获得其性别和年龄?

您需要稍微改变一下方法以传递更多参数。 您要请求的路径是: https://graph.facebook.com/me?access_token=access_token&fields=id,name,birthday,gender : https://graph.facebook.com/me?access_token=access_token&fields=id,name,birthday,gender

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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