【问题标题】:LinkedIn get people by Id in node.jsLinkedIn 在 node.js 中通过 ID 获取人员
【发布时间】:2016-12-30 22:25:36
【问题描述】:

我想使用 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 拒绝了所有获取请求?

【问题讨论】:

    标签: node.js api express linkedin


    【解决方案1】:

    使用这个

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

    插入

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-06-19
      • 1970-01-01
      • 2020-05-15
      • 1970-01-01
      • 2018-10-19
      相关资源
      最近更新 更多