shiqiyue-linkedin-private-api
Version:

263 lines • 11.3 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.ProfileRequest = void 0;
const LI_CDN = 'https://media-exp2.licdn.com/media';
class ProfileRequest {
constructor({ request }) {
this.request = request;
}
getProfile({ publicIdentifier }) {
const queryParams = {
q: 'memberIdentity',
memberIdentity: encodeURIComponent(publicIdentifier),
decorationId: this.request.decorationIds.FullProfileWithEntities,
};
return this.request.get('identity/dash/profiles', {
params: queryParams,
});
}
getProfile2({ publicIdentifier }) {
const queryParams = {
q: 'memberIdentity',
memberIdentity: encodeURIComponent(publicIdentifier),
decorationId: this.request.decorationIds.TopCardSupplementary,
};
return this.request.get('identity/dash/profiles', {
params: queryParams,
});
}
getOwnProfile() {
return this.request.get('me');
}
getFullProfile({ account }) {
if (!account) {
throw new Error('a public account is required');
}
const resources = ['profileView', 'profileContactInfo', 'highlights'];
return Promise.all(resources.map(resource => this._fetchProfileResource({ account, resource })))
.then((responses) => {
const fullProfile = { account };
responses.map(res => Object.assign(fullProfile, res));
return Promise.resolve(this._scrubFullProfileResponse({ profile: fullProfile }));
});
}
_fetchProfileResource({ account, resource }) {
let url = `/voyager/api/identity/profiles/${account}/`;
if (!resource) {
url += 'profileView';
}
else {
url += resource;
}
const headers = Object.assign(this.request.request.defaults.headers, {
accept: "*/*"
});
delete headers["x-restli-protocol-version"];
delete headers["x-li-page-instance"];
delete headers["x-li-track"];
return this.request.get(url, { headers: headers });
}
_scrubFullProfileResponse({ profile }) {
const socialProfile = {
source: 'LinkedIn',
firstname: undefined,
lastname: undefined,
headline: undefined,
industryName: undefined,
summary: undefined,
emailAddress: undefined,
location: undefined,
publicIdentifier: undefined,
occupation: undefined,
address: undefined,
birthdate: undefined,
phoneNumbers: undefined,
twitterHandles: undefined,
picture: undefined,
education: undefined,
patents: undefined,
publications: undefined,
projects: undefined,
positions: undefined,
languages: undefined,
skills: undefined,
websites: undefined
};
socialProfile.firstname = profile.profile.firstName || '';
socialProfile.lastname = profile.profile.lastName || '';
socialProfile.headline = profile.profile.headline || '';
socialProfile.industryName = profile.profile.industryName || '';
socialProfile.summary = profile.profile.summary || '';
socialProfile.location = profile.profile.locationName || '';
socialProfile.emailAddress = profile.emailAddress || '';
socialProfile.publicIdentifier = profile.publicIdentifier;
socialProfile.occupation = profile.profile.miniProfile.occupation || '';
socialProfile.address = profile.profile.address || '';
socialProfile.birthdate = profile.birthDateOn || {};
socialProfile.phoneNumbers = [];
socialProfile.twitterHandles = [];
socialProfile.picture = '';
if (profile.hasOwnProperty('phoneNumbers')) {
socialProfile.phoneNumbers = profile.phoneNumbers;
}
if (profile.hasOwnProperty('twitterHandles')) {
socialProfile.twitterHandles = profile.twitterHandles.map(twitter => twitter.name) || [];
}
if (profile.profile.hasOwnProperty('pictureInfo') &&
profile.profile.pictureInfo.hasOwnProperty('masterImage')) {
socialProfile.picture = `${LI_CDN}${profile.profile.pictureInfo.masterImage}`;
}
socialProfile.education = profile.educationView.elements.map(e => this._scrubEducationInfo(e)) || [];
socialProfile.patents = profile.patentView.elements.map(p => this._scrubPatentInfo(p)) || [];
socialProfile.publications = profile.publicationView.elements.map(p => this._scrubPublicationInfo(p)) || [];
socialProfile.projects = profile.projectView.elements.map(p => this._scrubProjectInfo(p)) || [];
socialProfile.positions = profile.positionView.elements.map(p => this._scrubPositionInfo(p)) || [];
socialProfile.languages = profile.languageView.elements.map(language => language.name) || [];
socialProfile.skills = profile.skillView.elements.map(skill => skill.name) || [];
if (profile.hasOwnProperty('websites') && profile.websites.length > 0) {
socialProfile.websites = profile.websites.map(w => this._scrubWebsiteInfo(w)) || [];
}
if (socialProfile.headline === socialProfile.occupation) {
const currentPositions = profile.positionView.elements
.filter(p => p.hasOwnProperty('timePeriod') && p.timePeriod.hasOwnProperty('startDate') && !p.timePeriod.hasOwnProperty('endDate')) || [];
const currentPosition = currentPositions[0] || {};
socialProfile.occupation = currentPosition.title || '';
}
return socialProfile;
}
_scrubEducationInfo(education) {
const educationInfo = {
activities: education.activities || '',
degreeName: education.degreeName || '',
fieldOfStudy: education.fieldOfStudy || '',
timePeriod: education.timePeriod || {},
schoolName: education.schoolName || '',
school: undefined
};
if (education.hasOwnProperty('school')) {
educationInfo.school = {
active: education.school.active || false,
name: education.school.schoolName || ''
};
if (education.school.hasOwnProperty('logo')) {
educationInfo.school.logo = this._scrubPathToResource(education.school.logo);
}
}
return educationInfo;
}
_scrubPathToResource(resource) {
if (resource.constructor !== Object) {
return '';
}
const key = Object.keys(resource)[0];
let resourcePath = resource[key].id || '';
if (resourcePath) {
resourcePath = `${LI_CDN}${resourcePath}`;
}
return resourcePath;
}
_scrubPositionInfo(position) {
let linkedInCompanyId = '';
if (position.companyUrn) {
const pieces = position.companyUrn.split(':');
linkedInCompanyId = parseInt(pieces[pieces.length - 1], 10) + '';
}
const positionInfo = {
locationName: position.locationName || '',
companyName: position.companyName || '',
linkedInCompanyId: linkedInCompanyId,
description: position.description || '',
timePeriod: position.timePeriod || {},
title: position.title || '',
company: undefined
};
if (position.hasOwnProperty('company')) {
positionInfo.company = {
employeeCountRange: position.company.employeeCountRange || {},
industries: position.company.industries || []
};
if (position.company.hasOwnProperty('miniCompany') &&
position.company.miniCompany.hasOwnProperty('logo')) {
positionInfo.company.logo = this._scrubPathToResource(position.company.miniCompany.logo);
}
}
return positionInfo;
}
_scrubWebsiteInfo(website) {
const categoryType = Object.keys(website.type)[0];
return {
website: website.url,
type: website.type[categoryType].category || 'Portfolio'
};
}
_scrubPublicationInfo(publication) {
const publicationInfo = {
date: publication.date || {},
description: publication.description || '',
name: publication.name || '',
publisher: publication.publisher || '',
url: publication.url || '',
authors: undefined
};
if (publication.hasOwnProperty('authors') && publication.authors.length > 0) {
publicationInfo.authors = publication.authors.map(author => this._scrubMemberInfo(author));
}
return publicationInfo;
}
_scrubMemberInfo(member) {
if (!member) {
return { firstname: '', lastname: '', occupation: '', publicIdentifier: '' };
}
const memberInfo = {
firstname: (member.member && member.member.firstName) ? member.member.firstName : '',
lastname: (member.member && member.member.lastName) ? member.member.lastName : '',
occupation: (member.member && member.member.occupation) ? member.member.occupation : '',
publicIdentifier: (member.member && member.member.publicIdentifier) ? member.member.publicIdentifier : '',
picture: undefined
};
if (member.member && member.member.hasOwnProperty('picture')) {
memberInfo.picture = this._scrubPathToResource(member.member.picture);
}
return memberInfo;
}
_scrubIdFromUrn(urn) {
if (!urn) {
return '';
}
const pieces = urn.split(':');
return parseInt(pieces[pieces.length - 1], 10);
}
_scrubPatentInfo(patent) {
const patentInfo = {
applicationNumber: patent.applicationNumber || '',
description: patent.description || '',
filingDate: patent.filingDate || {},
issueDate: patent.issueDate || {},
number: patent.number || '',
pending: patent.pending,
title: patent.title || '',
url: patent.url || '',
inventors: undefined
};
if (patent.hasOwnProperty('inventors') && patent.inventors.length > 0) {
patentInfo.inventors = patent.inventors
.filter(inventor => inventor.hasOwnProperty('member'))
.map(inventor => this._scrubMemberInfo(inventor.member));
}
return patentInfo;
}
_scrubProjectInfo(project) {
const projectInfo = {
description: project.description || '',
timePeriod: project.timePeriod || {},
title: project.title || '',
url: project.url || ''
};
if (project.hasOwnProperty('members') && project.members.length > 0) {
project.members = project.members.map(member => this._scrubMemberInfo(member));
}
return projectInfo;
}
}
exports.ProfileRequest = ProfileRequest;
//# sourceMappingURL=profile.request.js.map