- Notifications
You must be signed in to change notification settings - Fork6
👨💼 LinkedIn API for TypeScript
License
transitive-bullshit/linkedin-api
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
TypeScript client for LinkedIn's unofficial API.
This package provides a HTTP API client for accessing LinkedIn's readonly Voyager APIs. These are the same APIs that the official LinkedIn webapp uses to fetch data about user profiles, companies, and jobs.
No official API access is required. All you need is a valid LinkedIn user account (email and password).
Important
This library is not officially supported by LinkedIn. Using this library might violate LinkedIn's Terms of Service. Use it at your own risk.
npm install linkedin-api-fetch
import{LinkedInClient}from'linkedin-api-fetch'constlinkedin=newLinkedInClient({email:'todo@example.com',// defaults to LINKEDIN_EMAILpassword:'todo'// defaults to LINKEDIN_PASSWORD})constuser=awaitlinkedin.getProfile('fisch2')constcompany=awaitlinkedin.getCompany('microsoft')constschool=awaitlinkedin.getSchool('brown-university')constpeopleSearchResults=awaitlinkedin.searchPeople('travis fischer')constcompanySearchResults=awaitlinkedin.searchCompanies('openai')
LinkedIn's internal data format is pretty verbose, so these methods all normalize the raw responses into a more reasonable format. Most API methods include aRaw
version to return the original data:getProfileRaw
,getCompanyRaw
,getSchoolRaw
, etc.
LinkedInClient
will authenticate lazily using the provided email and password, or you can authenticate eagerly by callingLinkedInClient.ensureAuthenticated()
.
The resulting cookies are stored usingconf in a platform-dependent user data directory. You can access the cookie data vialinkedin.config.path
which will point to a path on your filesystem.
Auth cookies are re-initialized automatically either when they expire or when the client runs into a401
/403
HTTP error. You can force the auth cookie to refresh manually by callinglinkedin.authenticate()
which returns aPromise
.
If you want to force re-authentication and ignore the existing cookies, useLinkedInClient.authenticate()
.
Important
I recommend not using your personal LinkedIn account credentials with any LinkedIn scraping library unless you don't care about the possibility of being banned. Create a throwaway account for testing purposes.
It is highly recommended that you throttle your API requests to LinkedIn to avoid being blocked. The defaultLinkedInClient
adds a random delay between 1-5 seconds before each API request in order to try and evade detection. The default throttle also enforces a low rate-limit. It's easy to customize this default rate limit by disabling the defaultthrottle
and overriding the defaultky
instance:
import{LinkedInClient}from'linkedin-api-fetch'importpThrottlefrom'p-throttle'importthrottleKyfrom'throttle-ky'importkyfrom'ky'// Custom rate-limit allowing up to 1 request every 5 secondsconstthrottle=pThrottle({limit:1,interval:5*1000})constlinkedin=newLinkedInClient({// Override the default `ky` instance which all API requests will useky:throttleKy(ky,throttle),// Disable the default throttlingthrottle:false})
The easiest way to use a proxy with Node.jsfetch
is via undici'sEnvHttpProxyAgent, which will respect thehttp_proxy
,https_proxy
, andno_proxy
environment variables.
npm install undici
import{LinkedInClient}from'linkedin-api-fetch'import{EnvHttpProxyAgent}from'undici'importkyfrom'ky'constlinkedin=newLinkedInClient({ky:ky.extend({dispatcher:newEnvHttpProxyAgent()asany})})
LinkedIn will sometimes respond to authentication requests with a Challenge URL. This can happen if LinkedIn suspects your account is being used programatically (possibly a combination of IP-based, usage-based, and/or workload-based).
If you get aCHALLENGE
error, you'll need to manually log out and log back in to your account using a browser.
Known reasons for Challenge include:
- 2FA
- Rate-limit - "It looks like you’re visiting a very high number of pages on LinkedIn.". Note - n=1 experiment where this page was hit after ~900 contiguous requests in a single session (within the hour) (these included random delays between each request), as well as a bunch of testing, so who knows the actual limit.
If you get a 401 error when trying to authenticate, you likely need to log in via your browser. LinkedIn will sometimes see traffic as suspicious and require a combination of email code verification and CAPTCHA.
Once you can log in via a browser with being challenged with additional auth, then this library should be able to authenticate properly.
searchJobs()
- port more methods from the python versionhttps://github.com/tomquirk/linkedin-api
This library is not endorsed or supported by LinkedIn. It is an unofficial library intended for educational purposes and personal use only. By using this library, you agree to not hold the author or contributors responsible for any consequences resulting from its usage.
MIT ©Travis Fischer
This package is a TypeScript port of the popularPython linkedin-api.
If you found this project helpful, please consider starring it andfollowing me on Twitter.
About
👨💼 LinkedIn API for TypeScript