LINKEDIN प्रोफाइल API

JavaScript मध्ये LinkedIn प्रोफाइल API रिस्पॉन्स पार्स करा

JavaScript व TypeScript मध्ये LinkedIn प्रोफाइल API JSON पार्स करा: पूर्ण types, null व रिकाम्या याद्या, वर्ष-महिना तारखा, सध्याची भूमिका आणि flat rows.

लेखक: Surender Kumar, GTM Engineer, ProfileHunt · प्रकाशित: · 8 मिनिटांचे वाचन

इतर भाषांमध्ये: English · Español · Português (Brasil) · Deutsch · Français · 简体中文 · हिन्दी · العربية · বাংলা · Русский · Bahasa Indonesia · اردو · 日本語 · Tiếng Việt · తెలుగు · Hausa · Türkçe · தமிழ் · 한국어

JavaScript मध्ये LinkedIn प्रोफाइल API रिस्पॉन्स पार्स करा

JavaScript मध्ये LinkedIn प्रोफाइल API रिस्पॉन्स पार्स करण्यासाठी आधी त्याला टाइप द्या, मग तीन गोष्टी स्पष्टपणे हाताळा: null असलेली मूल्ये, [] असलेल्या याद्या, आणि LinkedIn च्या दोन तारीख स्वरूपांचा ("2014" आणि "2014-02"). ProfileHunt मध्ये प्रत्येक की नेहमी उपस्थित असते, त्यामुळे की अस्तित्वात आहे का हे तुम्ही कधीच तपासत नाही; तिचे मूल्य null आहे का ते तपासता. हे गाइड संपूर्ण TypeScript types, तारखा आणि सध्याच्या भूमिकेसाठी helpers, आणि प्रोफाइलला एका टेबल row मध्ये flatten करणारे function देते.

डेटा कुठून येतो हे LinkedIn प्रोफाइल API चा आढावा समजावतो; हा लेख तुमच्याकडे JSON आल्यानंतर सुरू होतो.

महत्त्वाचे मुद्दे

  • रिस्पॉन्सला status वर union म्हणून टाइप करा. status === "ok" नंतर TypeScript ला कळते की profile null नाही.
  • ?. आणि ?? वापरा, in कधीही नाही. Keys कधीच गहाळ होत नाहीत; मूल्ये null असू शकतात आणि याद्या रिकाम्या असू शकतात.
  • भूमिका आणि शाळांच्या तारखा strings आहेत, timestamps नाहीत. "2014" आणि "2014-02" दोन्ही येतात; new Date("2014") स्वतःहून 1 जानेवारी तयार करते.
  • सध्याची भूमिका म्हणजे end_date === null असलेली. त्या अनेक असू शकतात, आणि सार्वजनिक व्ह्यूमध्ये आधीच्या भूमिकांना title नसते.

रिस्पॉन्ससाठी TypeScript types

हे types profile endpoint संदर्भ आणि ProfileHunt होम पेजवरील नमुना रिस्पॉन्सेसनुसार आहेत. ते profilehunt.ts फाइलमध्ये पेस्ट करा:

export type Position = {
  company: string;
  company_url: string | null;
  title: string | null;       // current roles only
  location: string | null;
  description: string | null;
  start_date: string | null;  // "2014" or "2014-02"
  end_date: string | null;    // null = current role
};

export type School = {
  school: string;
  school_url: string | null;
  start_date: string | null;
  end_date: string | null;
};

export type Post = {
  url: string;
  posted_at: string;          // ISO 8601 UTC
  text: string | null;
  likes: number | null;
};

export type Article = {
  url: string;
  headline: string | null;
  image_url: string | null;
  published_at: string;       // ISO 8601 UTC
  likes: number | null;
};

export type Reaction = {
  verb: string;               // the kind of reaction, as LinkedIn labels it
  reacted_at: string;         // ISO 8601 UTC
  post_url: string | null;
  post_author: string | null; // profile name from the post URL
  post_at: string | null;
};

export type Comment = {
  verb: string;               // "commented on a post" or "replied to a comment"
  text: string | null;
  age: string;                // as LinkedIn shows it: "5h", "3d", "2w", "4mo", "1y"
  commented_at: string | null; // approximate: age counted back from scraped_at
  post_url: string | null;
  post_author: string | null;
  post_at: string | null;     // exact
};

export type Profile = {
  public_id: string;
  profile_url: string;
  full_name: string | null;
  first_name: string | null;
  last_name: string | null;
  photo_url: string | null;
  headline: string | null;
  about: string | null;
  location: string | null;
  country: string | null;     // two-letter code, e.g. "US"
  experience: Position[];
  education: School[];
  languages: string[];
  followers: number | null;
  connections: number | null; // 500 means 500 or more
  creator: boolean;
  badges: string[];
  last_post_at: string | null;
  recent_posts: Post[];
  recent_articles: Article[];
  last_reaction_at: string | null;
  recent_reactions: Reaction[];
  last_comment_at: string | null; // approximate, like commented_at
  recent_comments: Comment[];
  last_active_at: string | null;  // newest of last_post_at, last_reaction_at, last_comment_at
  scraped_at: string;         // ISO 8601 UTC
};

export type ProfileResult =
  | { status: "ok"; profile: Profile }
  | { status: "gone" | "unavailable"; profile: null };

API परत करते त्या सर्व keys या आहेत. Reaction आणि comment keys कधीही पोस्ट न करणाऱ्या लोकांचीही activity दाखवतात; commented_at अंदाजे आहे कारण LinkedIn फक्त 4w सारखे वय दाखवते, तर reacted_at आणि post_at अचूक आहेत. profile संदर्भात प्रत्येक फील्डवर टीप आहे.

ProfileResult मिळवण्यासाठी Node.js मधून LinkedIn प्रोफाइल API कॉल करणे मध्ये दाखवल्याप्रमाणे रिक्वेस्ट पाठवा आणि पार्स केलेली बॉडी cast करा: const result = (await res.json()) as ProfileResult.

एक अखंड स्लॅब आणि बारा भागांत विभागलेला स्लॅब शेजारी: फक्त वर्ष असलेली तारीख आणि वर्ष-महिना तारीख

अडचणीत आणणारी फील्ड्स पार्स करणे

प्रोफाइल पार्सिंगमधील बहुतेक bugs चार ठिकाणांहून येतात: nulls, तारखा, सध्याची भूमिका, आणि मर्यादित संख्या. प्रत्येकावर छोटा उपाय आहे.

Nulls आणि रिकाम्या याद्या

प्रोफाइल सार्वजनिकपणे न दाखवणारे मूल्य null असते; काहीच नसलेली यादी [] असते. त्यामुळे profile.experience.length नेहमी सुरक्षित आहे, आणि profile.experience[0] undefined असू शकते.

const name = profile.full_name ?? profile.public_id;
const firstSchool = profile.education[0]?.school ?? null;
const postCount = profile.recent_posts.length;

if ("headline" in profile) लिहू नका. ते नेहमी true असते, त्यामुळे खरा प्रश्न लपतो: headline null आहे का.

वर्ष व वर्ष-महिना तारखा

भूमिका आणि शाळांवरील start_date आणि end_date म्हणजे LinkedIn जे दाखवते तेच: Gates Foundation मधील Bill Gates साठी "2000", Microsoft मधील Satya Nadella साठी "2014-02". त्यांना Date ऐवजी भागांमध्ये पार्स करा:

export function parseYearMonth(d: string | null) {
  if (!d) return null;
  const [year, month] = d.split("-").map(Number);
  return { year, month: month ?? null }; // month is 1-12 or null
}

new Date("2014") 1 जानेवारी 2014 ची UTC मध्यरात्र परत करते, अशी अचूकता जी प्रोफाइलने कधीच दावा केली नव्हती. month: null ठेवा आणि प्रत्येक use case नुसार ठरवा, उदाहरणार्थ tenure अंदाजासाठी "वर्षाचा मध्य गृहीत धरा". Timestamps (posted_at, published_at, reacted_at, last_post_at, last_active_at, scraped_at आणि इतर) UTC मधील पूर्ण ISO 8601 strings आहेत, त्यामुळे त्यांच्यासाठी new Date(value) बरोबर आहे.

कच्च्या strings sort करणे चालते: साध्या string तुलनेत "2014" < "2014-02" < "2015".

सध्याची भूमिका

सध्याच्या भूमिकेला end_date: null असते. सार्वजनिक व्ह्यू title फक्त सध्याच्या भूमिकांसाठीच दाखवतो; आधीच्या भूमिका title: null सह परत येतात.

export function currentRoles(p: Profile) {
  return p.experience.filter(e => e.end_date === null);
}
export const currentRole = (p: Profile) => currentRoles(p)[0] ?? null;

Satya Nadella च्या नमुना प्रोफाइलमध्ये दोन सध्याच्या भूमिका आहेत: "2014-02" पासून Microsoft मध्ये Chairman and CEO, आणि "2018" पासून University of Chicago मध्ये Member Board Of Trustees. currentRole पहिली घेते, कारण experience प्रोफाइलमधील क्रम जसाच्या तसा ठेवते. तुम्हाला "नियोक्ता" हवा असेल तर ते सहसा बरोबर असते; प्रत्येक संलग्नता हवी असेल तर currentRoles वापरा.

मर्यादित आणि कमी संख्या

connections मर्यादित आहे: 500 च्या वर LinkedIn लॉग आउट असलेल्या visitors ना "500+" दाखवते, त्यामुळे 500 म्हणजे 500 किंवा अधिक. ते "500+" म्हणून दाखवा. कमी संख्याही खऱ्या असतात: Bill Gates च्या नमुन्यात followers: 40725248 शेजारी connections: 8 दिसते. पोहोचीसाठी followers वापरा.

const connectionsLabel = (n: number | null) => (n === null ? "" : n >= 500 ? "500+" : String(n));

nested boxes ना समान tiles च्या एका रांगेत सपाट करणारे प्रेस

प्रोफाइलला एका टेबल row मध्ये flatten करणे

Spreadsheets, CSV फाइल्स आणि SQL टेबल्सना प्रत्येक व्यक्तीसाठी एक flat row हवी असते. तुम्हाला लागणारे कॉलम्स निवडा आणि बाकीचे काढा:

export function toRow(p: Profile) {
  const role = currentRole(p);
  return {
    public_id: p.public_id,
    full_name: p.full_name ?? "",
    headline: p.headline ?? "",
    location: p.location ?? "",
    country: p.country ?? "",
    current_company: role?.company ?? "",
    current_title: role?.title ?? "",
    current_since: role?.start_date ?? "",
    latest_school: p.education[0]?.school ?? "",
    followers: p.followers ?? "",
    connections: connectionsLabel(p.connections),
    last_post_at: p.last_post_at ?? "",
    scraped_at: p.scraped_at,
  };
}

Satya Nadella नमुन्यावर चालवल्यास console.table([toRow(profile)]) हे देते:

कॉलममूल्य
full_nameSatya Nadella
headlineChairman and CEO at Microsoft
locationRedmond, Washington, United States
current_companyMicrosoft
current_titleChairman and CEO
current_since2014-02
latest_schoolThe University of Chicago Booth School of Business
followers12222008
connections500+
last_post_at2026-10-12T13:03:00.729Z

कच्चे JSON flat row च्या शेजारी ठेवा (एक jsonb कॉलम, किंवा JSONL फाइल). Row वाचण्यासाठी आणि filter करण्यासाठी आहे; JSON मुळे प्रोफाइल पुन्हा fetch न करता नंतर कॉलम जोडता येतो. यादी आत, फाइल बाहेर अशा संपूर्ण स्क्रिप्टसाठी Node.js एनरिचमेंट वर्कफ्लो पाहा.

बहुतेक गाइड्स कुठे चुकतात

ते प्रत्येक फील्ड optional म्हणून मॉडेल करतात. headline?: string लिहिल्याने TypeScript ला वाटते की की गहाळ असू शकते, जे कधीच होत नाही. headline: string | null अचूक आहे आणि compiler ला योग्य प्रश्न विचारायला लावते.

ते प्रत्येक तारीख new Date() ने पार्स करतात. त्यामुळे "2014" अचूक timestamp बनते आणि tenure चे गणित प्रत्यक्षात नसताना अचूक दिसते.

ते experience[0] ला सध्याची नोकरी समजतात. ती यादीतील पहिली भूमिका आहे, जी कदाचित संपलेली असेल. आधी end_date === null वर filter करा.

गैरसमज आणि वास्तव

गैरसमजवास्तव
"TypeScript types API रिस्पॉन्स validate करतात."Runtime ला types नाहीसे होतात. as ProfileResult हे तुम्ही दिलेले वचन आहे; त्याची अंमलबजावणी runtime check करते.
"रिकामे experience म्हणजे त्या व्यक्तीला नोकरी नाही."त्याचा अर्थ सार्वजनिक व्ह्यू कोणतीही भूमिका दाखवत नाही. अनेक सदस्य लॉग आउट असलेल्या visitors पासून तपशील लपवतात.
"जुन्या भूमिकेवरील title: null हा पार्सिंग bug आहे."सार्वजनिक व्ह्यूमध्ये आधीच्या भूमिकांचे titles नसतात. null हेच योग्य मूल्य आहे.
"connections: 500 म्हणजे नेमके 500."त्याचा अर्थ 500 किंवा अधिक.

प्रगत: runtime checks आणि generated types

एका सर्व्हिससाठी हाताने लिहिलेले types पुरेसे आहेत. अनेक सर्व्हिसेस तोच डेटा वापरत असतील तेव्हा दोन सुधारणा उपयोगी पडतात.

OpenAPI spec मधून types generate करा. ProfileHunt त्याची स्कीमा /openapi.json वर प्रकाशित करते, ज्यात Profile, Position, School, Post, Article, Reaction आणि Comment ही नावे असलेल्या schemas आहेत. openapi-typescript सारखा generator त्यांचे types बनवतो, त्यामुळे पुन्हा generate केल्यावर नवीन फील्ड तुमच्या editor मध्ये दिसते.

सीमेवर तपासा, आत विश्वास ठेवा. JSON तुमच्या सिस्टममध्ये जिथे येते तिथे एकदाच validate करा: API कॉल करणाऱ्या function मध्ये, किंवा जिथे साठवलेले JSON परत वाचता तिथे. इतका छोटा guard बहुतेक अनपेक्षित गोष्टी पकडतो:

function isProfileResult(x: any): x is ProfileResult {
  return (x?.status === "ok" && typeof x.profile?.public_id === "string")
    || ((x?.status === "gone" || x?.status === "unavailable") && x.profile === null);
}

Zod सारखी schema लायब्ररी तोच check फील्ड-स्तरावरील errors सह देते. कोणत्याही प्रकारे, सीमेपलीकडील सगळे types वर अवलंबून राहू शकते.

ProfileHunt कुठे बसते

ProfileHunt हे LinkedIn Profile API आहे: सार्वजनिक LinkedIn प्रोफाइल URL आत, JSON बाहेर, प्रत्येक रिस्पॉन्समध्ये त्याच keys सह. हीच स्थिरता वरचे पार्सिंग छोटे ठेवते: कोणतेही key checks नाहीत, एक null नियम, एक तारीख नियम.

सापडलेल्या प्रत्येक प्रोफाइलला एक क्रेडिट लागते, 1,000 प्रोफाइलसाठी $0.50, आणि gone किंवा unavailable साठी काहीच नाही. ते फक्त सार्वजनिक व्ह्यू परत करते, त्यामुळे ईमेल नाहीत, फोन नंबर नाहीत, आधीच्या भूमिकांचे titles नाहीत, आणि connections 500 वर मर्यादित आहे.

सुरुवात कशी करावी

  1. profilehunt.dev/login वर साइन इन करा: कामाच्या ईमेलसह 100 मोफत क्रेडिट्स, वैयक्तिक ईमेलसह 10.
  2. एक प्रोफाइल fetch करा आणि JSON फाइलमध्ये सेव्ह करा.
  3. वरचे types पेस्ट करा, त्यावर toRow चालवा, आणि LinkedIn प्रोफाइल JSON स्कीमा शी तुलना करा. Python मध्ये काम करता? Python ने प्रोफाइल JSON पार्स करणे पाहा.

API म्हणजे काय आणि त्यात काय येते हे पाहण्यासाठी LinkedIn प्रोफाइल API च्या आढाव्याकडे परत जा.

वारंवार विचारले जाणारे प्रश्न

LinkedIn प्रोफाइल JSON मधून एखाद्याची सध्याची नोकरी कशी मिळवावी?

experience मधून end_date === null असलेल्या नोंदी filter करा. पहिली नोंद म्हणजे प्रोफाइलवर पहिली दिलेली भूमिका; एकापेक्षा जास्त सध्याच्या भूमिका असू शकतात.

LinkedIn API रिस्पॉन्समध्ये आधीच्या नोकऱ्यांचे title null का असते?

LinkedIn चा सार्वजनिक प्रोफाइल व्ह्यू आधीच्या भूमिकांचे titles दाखवत नाही, त्यामुळे ProfileHunt त्यांच्यासाठी title: null परत करते. कंपनी आणि तारखा तरीही असतात.

"2014-02" सारख्या LinkedIn तारखा JavaScript Date मध्ये कशा बदलाव्या?

new Date() कॉल करण्याऐवजी - वर split करून वर्ष आणि optional महिना काढा. Date हवीच असेल तर दिवस तुम्ही स्वतः निवडा, उदाहरणार्थ new Date(Date.UTC(year, (month ?? 1) - 1, 1)), आणि लक्षात ठेवा की प्रोफाइलने फक्त वर्ष किंवा वर्ष-महिना दिला होता.

LinkedIn प्रोफाइल API साठी TypeScript types आहेत का?

तुम्ही या लेखातील types कॉपी करू शकता, किंवा openapi-typescript सारख्या टूलने ProfileHunt च्या /openapi.json वरील OpenAPI spec मधून ते generate करू शकता.

JavaScript मध्ये LinkedIn प्रोफाइल JSON चे CSV कसे करावे?

प्रत्येक प्रोफाइलला strings आणि numbers च्या एका ऑब्जेक्टमध्ये flatten करा (नाव, हेडलाइन, सध्याची कंपनी, फॉलोअर्स), मग प्रत्येक ऑब्जेक्टसाठी एक ओळ लिहा, आणि comma किंवा quotes असलेली मूल्ये quote करा.

API की मिळवा कामाच्या ईमेलसह 100 मोफत क्रेडिट्स