added connections

This commit is contained in:
2024-05-31 15:49:51 -04:00
parent beafea2b43
commit 97ec9c9f87
6 changed files with 67 additions and 22 deletions
+47
View File
@@ -226,6 +226,53 @@ export default class linkedInAPIClass {
}
/**
* @param {number[]} conDeg
* @param {number} [limit=1000]
*/
async getConnections(entityNameJoined, entityUrn, conDeg, limit = 1000, start = 0) {
const empAll = [];
if (this.logAll) console.log(`scanning for ${limit} connections for user "${entityNameJoined}"`);
const lb = (this.logAll) ? new LoadingBar(Math.round(limit / 50)) : null;
for (let i = start; empAll.length < limit; i += 50) {
let urlExt = `variables=(start:${i},origin:MEMBER_PROFILE_CANNED_SEARCH,memberIdentity:${entityNameJoined},query:(flagshipSearchIntent:SEARCH_SRP,queryParameters:List((key:connectionOf,value:List(${entityUrn})),(key:network,value:List(${numToConDegs(conDeg)})),(key:resultType,value:List(PEOPLE))),includeFiltersInResponse:false))`;
const r = await this._makeReq(urlExt);
if (!r?.included && r?.data?.errors) {
console.error(JSON.stringify(r.data.errors))
throw "ERROR!";
}
else if (!r?.data.included) break;
empAll.push(r);
if (this.logAll) lb.increment(Math.ceil(r.included.length / 50));
await this.evade();
}
return empAll.flat();
}
async sendConnectionRequest(memberURN, customMessage = undefined) {
await this.evade();
const rPath = 'https://www.linkedin.com/voyager/api/voyagerRelationshipsDashMemberRelationships?action=verifyQuotaAndCreateV2&decorationId=com.linkedin.voyager.dash.deco.relationships.InvitationCreationResultWithInvitee-2';
const body = {
"invitee":
{ "inviteeUnion": { "memberProfile": `urn:li:fsd_profile:${memberURN}` } },
customMessage
}
const headers = this.headers;
headers['x-li-pem-metadata'] = 'Voyager - Invitations - Actions=invite-send';
const r = await axios.post(rPath, body, { headers }); // await axios.get(rPath, body, { headers }).catch(_ => null).then(_ => null).finally(() => axios.post(rPath, body, { headers }));
return r.data;
}
/**
* @returns {Promise<LinkedInProfile[]>}
* @param {String} keyword the user to search for
+17
View File
@@ -1,4 +1,5 @@
import linkedInAPIClass from "../index.js";
import { numToConDegs } from "./API.js";
export class LinkedInProfile {
/** @type {linkedInAPIClass} */
@@ -29,12 +30,28 @@ export class LinkedInProfile {
return '';
}
/**
* @param {number[]} conDeg
* @param {number} [limit=1000]
*/
async getConnections (conDeg, limit = 1000) {
if (!this.isConnected) throw `USER ${this.name} IS OUT OF NETWORK!`;
return await this.#APIRef.getConnections(this.entityNameJoined, this.entityUrn, conDeg, limit);
}
/**
* will send a friend request to this person
* @param {string} message
*/
makeConnection = (message) => this.#APIRef.sendConnectionRequest(this.entityUrn, message);
constructor(jsonData, apiRef) {
this.#APIRef = apiRef;
this.name = jsonData.title ? jsonData.title.text : '';
this.entityNameJoined = jsonData.navigationUrl?.split("/in/")[1]?.split("?")[0];
this.profileUrl = jsonData.navigationUrl || '';
this.trackingUrn = jsonData.trackingUrn || '';
this.isConnected = (jsonData.entityCustomTrackingInfo?.memberDistance !== 'OUT_OF_NETWORK');
const match = jsonData.entityUrn?.match(/urn:li:fsd_profile:(.*?),/);
this.entityUrn = match ? match[1] : '';