Npm包和流星

时间:2014-05-15 00:03:52

标签: javascript node.js meteor npm

我真的在与Meteor和NPM包node-linkedin进行斗争。

我理解NPM集成应该如何工作。我使用Meteorite和node-linkedin将NPM添加到packages.js。然后我通过Meteor.require()调用NPM包。

这是我的server / linkedin.js文件:

function Linkedin(accessToken) {
  this.linkedin = Meteor.require('node-linkedin')('api', 'secret', 'callback');
  this.accessToken = accessToken;
  this.linkedin.init(this.accessToken);
}

Linkedin.prototype.company = function() {
  var self = this;
  var data = Meteor.sync(function(done) {
    self.linkedin.companies.company('162479', function(err, res) {
      done(null, res);
    });
  });
  return data.result;
}

Meteor.methods({
  getCompanyInfo: function () {
    var linkedin = new Linkedin(Meteor.user().services.linkedin.accessToken);
    var data = linkedin.company();
    return data;
  }
});

不幸的是,当我调用getCompanyInfo()时它不起作用...我收到以下错误:"无法调用方法' company'未定义"。

Linkedin Auth工作正常(感谢accounts-linkedin)。但我还需要连接到Linkedin API。

我之前曾跟随this article在Meteor中使用FB Graph API。一切都很好。

问题可能来自Metheor.require()。我想知道我应该怎么做Metheor.require()中的第二组参数。我应该将这些npm包添加到packages.json中吗? Method.require()是否正确处理了第二组参数?

感谢您的帮助!

0 个答案:

没有答案