我无法连接到Linkedin
. 我必须使用nodejs
and 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");