1

我无法连接到Linkedin. 我必须使用nodejsand express,并且正在使用 linkedin-js 客户端 ( https://github.com/masylum/linkedin-js)。我到处寻找示例,但仍然不太了解如何进行“获取”调用并在页面上显示用户连接。当我使用“render”时出现错误,但是当我尝试使用“send”时,我发现 API 调用无论如何都不起作用。任何人的帮助和解释将不胜感激!这是我到目前为止所拥有的。

var express = require('express')
, linkedin_client = require('linkedin-js')('xxx', 'xxx', 'http://localhost:3003/')
, app = express();

app.configure(function(){

app.use(express.bodyParser());
app.use(express.methodOverride());
app.use(express.static(__dirname + '/'));
app.use(express.cookieParser());
app.use(express.session({ secret: "string" }));  
});
app.get('/', function (req, res) {
// the first time will redirect to linkedin
 linkedin_client.getAccessToken(req, res, function (error, token) {
// will enter here when coming back from linkedin
req.session.token = token;


 linkedin_client.apiCall('GET', '/people/~/connections:(headline,first-name,last-name)',
{
  token: {
    oauth_token_secret: req.session.token.oauth_token_secret
  , oauth_token: req.session.token.oauth_token
  }
, fields: req.param('id')//not sure?
}
, function (error, result) {
  res.send('message_sent');
}
);
//res.render('auth');  I'm getting an error here as well
});
});



app.post('/message', function (req, res) {
linkedin_client.apiCall('POST', '/people/~/shares',
{
  token: {
    oauth_token_secret: req.session.token.oauth_token_secret
  , oauth_token: req.session.token.oauth_token
  }
, share: {
    comment: req.param('message')
  , visibility: {code: 'anyone'}
  }
}
, function (error, result) {
  res.render('message_sent');
}
);
});





app.listen(3003);
console.log("Listening");
4

1 回答 1

0

在第二行,用您自己的https://www.linkedin.com/secure/developer替换“API Key”和“Secret Key” :

var express = require('express'),
    linkedin_client = require('linkedin-js')('API Key', 'Secret Key', 'http://localhost:3003/'),
    bodyParser = require('body-parser'),
    cookieParser = require('cookie-parser'),
    methodOverride = require('method-override'),
    session = require('express-session'),
    app = express();

app.use(bodyParser.json()); //basic app set up
app.use(bodyParser.urlencoded({extended: true}));
app.use(methodOverride());
app.use(express.static(__dirname + '/'));
app.use(cookieParser());
app.use(session({secret: 'secret',
    saveUninitialized: true,
    resave: true})); //session stuff
app.get('/', function (req, res) {
// the first time will redirect to linkedin
linkedin_client.getAccessToken(req, res, function (error, token) {
// will enter here when coming back from linkedin
req.session.token = token;

linkedin_client.apiCall('GET', '/people/~/connections:(headline,first-name,last-name)',
{
  token: {
    oauth_token_secret: req.session.token.oauth_token_secret
  , oauth_token: req.session.token.oauth_token
  }
, fields: req.param('id')//not sure?
}
, function (error, result) {
  res.send(result);
}
);

});
});

app.post('/message', function (req, res) {
linkedin_client.apiCall('POST', '/people/~/shares',
{
  token: {
    oauth_token_secret: req.session.token.oauth_token_secret
  , oauth_token: req.session.token.oauth_token
  }
, share: {
    comment: req.param('message')
  , visibility: {code: 'anyone'}
  }
}
, function (error, result) {
  res.render('message_sent');
}
);
});

app.listen(3003);
console.log("Listening");

于 2014-09-18T12:12:47.417 回答