ArkeologeN / node-linkedin

LinkedIn 2.0 wrapper in Node.js
MIT License
163 stars 79 forks source link

inherits.js Cannot read property 'version' of undefined #83

Closed mbielkin closed 6 years ago

mbielkin commented 6 years ago

Hi there. I occurred the next issue:

Error: TypeError: Cannot read property 'version' of undefined at .....\node_modules\node-linkedin\lib\inherits.js:20:39 at Object.share (......\node_modules\node-linkedin\lib\services\companies.js:80:116)

Here is how I use your library: Authorize and call callback endpoint successfully. Save accessToken into the object. Then I call

this.LinkedInConnection.init(this.accessToken);
return new Promise((resolve, reject) => {
    const params = {comment: message};
    linkedIn.companies.share(process.env.LINKEDIN_COMPANY_ID, params, function(err, company) {
      console.log('================');
      console.log(err, company);
      resolve(company.message);
    });
  });

Could you please tell me, what I do wrong. Or may be there is an issue in the library. Thanks.

ArkeologeN commented 6 years ago

It happens because it cannot locate accessToken internally. Please check if this.accessToken that you passed is a valid one.

Also, the ideal way to use should be:

const linkedIn = this.LinkedInConnection.init(this.accessToken); // this returns an instance initiated with access token.
return new Promise((resolve, reject) => {
  linkedIn.companies.share(process.env. LINKEDIN_COMPANY_ID, params, (err, company) => {
    if (err) return reject(err);
    return resolve(company);
  });
});

PS: I'm re-writing whole library to ONLY support promises and up-to-date test covered code. It is very unstable and under-development (don't know when would it be live!) but you may keep an eye over it so you don't have to wrap promises anymore :)

Have a look node-linked@v2.0!

mbielkin commented 6 years ago

@ArkeologeN Thanks, the issue really was connected to accessToken. Now everything works fine. Obviously will upgrade to v2.0 after it go live.