LinkedIn在node.js中通过Id获取人员

时间:2016-02-12 17:22:59

标签: node.js api express linkedin

我想通过Node.js从LinkedIn的API获取一些数据。 我按照本教程https://www.npmjs.com/package/node-linkedin编写了这个程序,用于在回调中将数据发送到控制台。

var Linkedin = require('node-linkedin')('XXX', 'XXX', 'http://localhost:3000/oauth/linkedin/callback');
var express = require('express');

var app = express()
    // Initialize 
var scope = ['r_basicprofile', 'r_emailaddress'];


var linkedinVariables = {
    'accessToken': null,
    'client': null
}

app.get('/oauth/linkedin', function(req, res) {
    // This will ask for permisssions etc and redirect to callback url. 
    Linkedin.auth.authorize(res, scope);
});

app.get('/oauth/linkedin/callback', function(req, res) {
    Linkedin.auth.getAccessToken(res, req.query.code, req.query.state, function(err, results) {
        if (err)
            return console.error(err);

        console.log(results);

        linkedinVariables.accessToken = results.access_token;

        console.log("ACCESS TOKEN IS ", linkedinVariables.accessToken);

        linkedinVariables.client = Linkedin.init(linkedinVariables.accessToken);

    /*  linkedinVariables.client.people.me(function(err, $in) {
            console.log($in);
        });*/

/*linkedinVariables.client.people.me('linkedin_id', ['id', 'first-name', 'last-name'], function(err, $in) {
    // Loads the profile by id.
    console.log($in);
});*/
        linkedinVariables.client.people.id('HM3nX8nJD6', function(err, $in) {
            console.log($in)
        });
        // return res.redirect('/');
    });
});

app.listen(3000);

现在这个程序工作正常,我用这一行得到数据:

linkedinVariables.client.people.me('linkedin_id', ['id', 'first-name', 'last-name'], function(err, $in) {
        // Loads the profile by id.
        console.log($in);
    });

在我的控制台中给我一个JSON响应,但是按照教程我可以通过ID获取有关公司和人员的其他信息,但即使我使用自己的ID获取自己的信息,响应也是空白的。 我的代码有问题或者LinkedIn拒绝所有请求吗?

1 个答案:

答案 0 :(得分:0)

使用此

var scope = ['r_basicprofile', 'r_fullprofile', 'r_emailaddress', 'r_network', 'r_contactinfo', 'rw_nus', 'rw_groups', 'w_messages'];

insted of

var scope = ['r_basicprofile', 'r_emailaddress'];