mirror of
https://github.com/ION606/linkedin-api.git
synced 2026-05-14 22:06:54 +00:00
fixed query params format
This commit is contained in:
@@ -130,3 +130,5 @@ dist
|
|||||||
.pnp.*
|
.pnp.*
|
||||||
|
|
||||||
temp.js
|
temp.js
|
||||||
|
config.json
|
||||||
|
cookie.txt
|
||||||
|
|||||||
+16
-14
@@ -46,7 +46,7 @@ function parseIncludedData(included, APIRef, excludeGeneric = false) {
|
|||||||
|
|
||||||
// APIRef may be ignored here
|
// APIRef may be ignored here
|
||||||
return new EntityClass(item, APIRef);
|
return new EntityClass(item, APIRef);
|
||||||
}).filter(o => (excludeGeneric && o instanceof Company) || (!excludeGeneric && o));
|
}).filter(o => (excludeGeneric && (o instanceof Company)) || (!excludeGeneric && o));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -58,7 +58,7 @@ export async function parseResponse(data, APIRef, excludeGeneric) {
|
|||||||
|
|
||||||
|
|
||||||
function findRangeIndex(number) {
|
function findRangeIndex(number) {
|
||||||
const rangeMap = ["B", "C", "D", "E", "F", "G", "H", "I"]
|
const rangeMap = ["B", "C", "D", "E", "F", "G", "H", "I"];
|
||||||
const companySizeRanges = [
|
const companySizeRanges = [
|
||||||
[1, 10],
|
[1, 10],
|
||||||
[11, 50],
|
[11, 50],
|
||||||
@@ -89,7 +89,7 @@ export function numsToSizes(...nums) {
|
|||||||
|
|
||||||
const ranges = nums.map(findRangeIndex);
|
const ranges = nums.map(findRangeIndex);
|
||||||
if (ranges.includes(-1)) throw `${nums} CONTAINS AN INVALID RANGE!`;
|
if (ranges.includes(-1)) throw `${nums} CONTAINS AN INVALID RANGE!`;
|
||||||
return `[${ranges.join("%2C")}]`;
|
return `[${ranges.join(",")}]`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -195,10 +195,14 @@ export default class linkedInAPIClass {
|
|||||||
* @param {boolean} [excludeGeneric=false]
|
* @param {boolean} [excludeGeneric=false]
|
||||||
* @returns {Promise<[SocialActivityCounts | Group | Company | GenericEntity]>}
|
* @returns {Promise<[SocialActivityCounts | Group | Company | GenericEntity]>}
|
||||||
*/
|
*/
|
||||||
async searchCompanies(keyword, numEmp, start = 0, castToClass = true, excludeGeneric = false) {
|
async searchCompanies(keyword, numEmp = undefined, start = 0, castToClass = true, excludeGeneric = false) {
|
||||||
let urlExt = `variables=(start:${start},origin:GLOBAL_SEARCH_HEADER,query:(keywords:${keyword},flagshipSearchIntent:SEARCH_SRP,queryParameters:List((key:resultType,value:List(COMPANIES))),includeFiltersInResponse:false))`;
|
let urlExt = `variables=(start:${start},origin:GLOBAL_SEARCH_HEADER,query:(keywords:${keyword},flagshipSearchIntent:SEARCH_SRP,queryParameters:List((key:resultType,value:List(COMPANIES))${(numEmp) ? `(key:companySize,value:List(${numsToSizes(...numEmp)}))` : ''}),includeFiltersInResponse:false))`;
|
||||||
if (numEmp) urlExt += `&companySize=${numsToSizes(...numEmp)}`;
|
|
||||||
const r = await this._makeReq(urlExt);
|
const r = await this._makeReq(urlExt);
|
||||||
|
|
||||||
|
if (!r?.included && r?.data?.errors) {
|
||||||
|
console.error(JSON.stringify(r.data.errors))
|
||||||
|
throw "ERROR!";
|
||||||
|
}
|
||||||
if (!castToClass) return r;
|
if (!castToClass) return r;
|
||||||
else return parseResponse(r, this, excludeGeneric);
|
else return parseResponse(r, this, excludeGeneric);
|
||||||
}
|
}
|
||||||
@@ -207,7 +211,7 @@ export default class linkedInAPIClass {
|
|||||||
/**
|
/**
|
||||||
* @returns {Promise<LinkedInProfile[]>}
|
* @returns {Promise<LinkedInProfile[]>}
|
||||||
* @param {String} keyword the user to search for
|
* @param {String} keyword the user to search for
|
||||||
* @param {Number?} [limit=1000]
|
* @param {Number?} [limit=1000] the function will find the bound the given number is contained in (see {@link findRangeIndex} for ranges)
|
||||||
* @param {boolean?} [castToClass=true] whether the function should return a list of Company classes or just raw JSON
|
* @param {boolean?} [castToClass=true] whether the function should return a list of Company classes or just raw JSON
|
||||||
* @param {Array<String>?} currentCompanies
|
* @param {Array<String>?} currentCompanies
|
||||||
* @param {Array<1 | 2 | 3>?} conDeg the level(s) of connection to include (defults to all)
|
* @param {Array<1 | 2 | 3>?} conDeg the level(s) of connection to include (defults to all)
|
||||||
@@ -219,16 +223,14 @@ export default class linkedInAPIClass {
|
|||||||
const empAll = [];
|
const empAll = [];
|
||||||
for (let i = 0; i < limit; i += 50) {
|
for (let i = 0; i < limit; i += 50) {
|
||||||
if (empAll.length >= limit) break;
|
if (empAll.length >= limit) break;
|
||||||
let urlExt = `includeWebMetadata=true&variables=(start:${i},query:(keywords:${keyword},flagshipSearchIntent:SEARCH_SRP,queryParameters:List((key:resultType,value:List(PEOPLE)))))`;
|
let urlExt = `includeWebMetadata=true&variables=(start:${i},query:(keywords:${keyword},flagshipSearchIntent:SEARCH_SRP,queryParameters:List((key:resultType,value:List(PEOPLE))`;
|
||||||
|
|
||||||
if (currentCompanies.length) urlExt += `¤tCompany=["${currentCompanies.join('"%2C"')}"]`;
|
if (currentCompanies.length) urlExt += `,(key:currentCompany,value:List(${currentCompanies.join(',')}))`;
|
||||||
if (conDeg.length) {
|
if (conDeg.length) urlExt += `,(key:network,value:List(${numToConDegs(conDeg)}))`;
|
||||||
const conFiltered = numToConDegs(conDeg);
|
urlExt += ')))';
|
||||||
if (conFiltered.length) urlExt += `network=["${currentCompanies.join('"%2C"')}"]}`
|
|
||||||
}
|
|
||||||
|
|
||||||
const r = await this._makeReq(urlExt);
|
const r = await this._makeReq(urlExt);
|
||||||
if (!r) return [];
|
if (!r?.included?.length) return [];
|
||||||
|
|
||||||
const filtered = r.included.filter(e => e.template === 'UNIVERSAL');
|
const filtered = r.included.filter(e => e.template === 'UNIVERSAL');
|
||||||
|
|
||||||
|
|||||||
+6
-2
@@ -1,7 +1,8 @@
|
|||||||
|
import linkedInAPIClass from "../index.js";
|
||||||
import { LinkedInProfile } from "./Profile.js";
|
import { LinkedInProfile } from "./Profile.js";
|
||||||
|
|
||||||
export class Company {
|
export class Company {
|
||||||
/** @type {import('../index.js').linkedInAPIClass} */
|
/** @type {linkedInAPIClass} */
|
||||||
#APIRef;
|
#APIRef;
|
||||||
|
|
||||||
|
|
||||||
@@ -44,8 +45,10 @@ export class Company {
|
|||||||
* @returns {Promise<JSON[] | LinkedInProfile[]>}
|
* @returns {Promise<JSON[] | LinkedInProfile[]>}
|
||||||
* @param {string} name
|
* @param {string} name
|
||||||
* @param {boolean} raw
|
* @param {boolean} raw
|
||||||
|
* @param {number} limit
|
||||||
|
* @note this function calls {@link linkedInAPIClass.searchEmployees}
|
||||||
*/
|
*/
|
||||||
searchEmployees = (name, limit=1000, raw=false) => this.#APIRef.searchEmployees(name, limit, !raw, [this.urn]);
|
searchEmployees = (name, limit = 1000, raw = false) => this.#APIRef.searchEmployees(name, limit, !raw, [this.entityNum]);
|
||||||
|
|
||||||
async getInfo() {
|
async getInfo() {
|
||||||
const toAdd = `q=universalName&universalName=${this.urn}`;
|
const toAdd = `q=universalName&universalName=${this.urn}`;
|
||||||
@@ -64,6 +67,7 @@ export class Company {
|
|||||||
this.name = data.title.text;
|
this.name = data.title.text;
|
||||||
this.urn = data.entityUrn;
|
this.urn = data.entityUrn;
|
||||||
this.url = data.navigationUrl;
|
this.url = data.navigationUrl;
|
||||||
|
this.entityNum = data.trackingUrn.replace('urn:li:company:', '');
|
||||||
|
|
||||||
if (!this.checkIfCompleted()) throw "NOT ALL NEEDED PARAMS FOUND!";
|
if (!this.checkIfCompleted()) throw "NOT ALL NEEDED PARAMS FOUND!";
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,14 @@
|
|||||||
|
import LinkedInAPIClass from "../index.js";
|
||||||
|
import fs from 'fs';
|
||||||
|
|
||||||
|
(async () => {
|
||||||
|
const LAPI = new LinkedInAPIClass();
|
||||||
|
|
||||||
|
const o = JSON.parse(fs.readFileSync('config.json'));
|
||||||
|
await LAPI.login(o.email, o.password);
|
||||||
|
|
||||||
|
const c = await LAPI.searchCompanies('microsoft', undefined, 0, true, true);
|
||||||
|
|
||||||
|
const managers = await c.find(o => (o.name === 'Microsoft')).searchEmployees('manager', 5);
|
||||||
|
console.log(managers, managers.length);
|
||||||
|
})();undefined
|
||||||
Reference in New Issue
Block a user