• Stars
    star
    1,941
  • Rank 23,875 (Top 0.5 %)
  • Language
    Python
  • License
    MIT License
  • Created over 6 years ago
  • Updated 2 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

πŸ‘¨β€πŸ’Ό LinkedIn API for Python

Linkedin API for Python

Sponsors

Lix proxycurl serpsbot piloterr

Become a sponsor

Programmatically send messages, get jobs, and search profiles with a regular Linkedin user account.

No "official" API access required - just use a valid Linkedin account!

Caution: This library is not officially supported by LinkedIn. Using it might violate LinkedIn's Terms of Service. Use it at your own risk.

Installation

Python >= 3.6 required

To install the linkedin_api package, use the following command:

pip3 install git+https://github.com/tomquirk/linkedin-api.git

Quick Start

See all methods on the documentation website.

Below is a basic example of how to use linkedin_api:

from linkedin_api import Linkedin

# Authenticate using any Linkedin account credentials
api = Linkedin('[email protected]', '*******')

# GET a profile
profile = api.get_profile('billy-g')

# GET a profiles contact info
contact_info = api.get_profile_contact_info('billy-g')

# GET 1st degree connections of a given profile
connections = api.get_profile_connections('1234asc12304')

Commercial Alternative

This is a sponsored section

Scrape public LinkedIn profile data at scale with Proxycurl APIs.

  • Scraping Public profiles are battle tested in court in HiQ VS LinkedIn case.
  • GDPR, CCPA, SOC2 compliant
  • High rate limit - 300 requests/minute
  • Fast - APIs respond in ~2s
  • Fresh data - 88% of data is scraped real-time, other 12% are not older than 29 days
  • High accuracy
  • Tons of data points returned per profile

Built for developers, by developers.

End sponsored section

Documentation

For comprehensive documentation, including available methods and parameters, visit the documentation.

Learn more about how it works.

Disclaimer

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.

Contributing

We welcome contributions! Learn how to find endpoints

Development Setup

Dependencies

  • Python 3.7
  • A valid Linkedin user account (don't use your personal account, if possible)
  • pipenv (optional)

Development installation

  1. Create a .env config file. An example is provided in .env.example - you include at least all of the settings set there.

  2. Using pipenv...

    pipenv install --dev
    pipenv shell

Running tests

python -m pytest tests

Troubleshooting

I keep getting a CHALLENGE

Linkedin will throw you a curve ball in the form of a Challenge URL. We currently don't handle this, and so you're kinda screwed. We think it could be only IP-based (i.e. logging in from different location). Your best chance at resolution is to log out and log back in on your 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.

Please add more as you come across them.

Search problems

  • Mileage may vary when searching general keywords like "software" using the standard search method. They've recently added some smarts around search whereby they group results by people, company, jobs etc. if the query is general enough. Try to use an entity-specific search method (i.e. search_people) where possible.

How it works

Before using this project, please consult the Terms and Conditions and Legal Notice.

This project attempts to provide a simple Python interface for the Linkedin API.

Do you mean the legit Linkedin API?

NO! To retrieve structured data, the Linkedin Website uses a service they call Voyager. Voyager endpoints give us access to pretty much everything we could want from Linkedin: profiles, companies, connections, messages, etc. - anything that you can see on linkedin.com, we can get from Voyager.

This project aims to provide complete coverage for Voyager.

How does it work?

In-depth overview

Voyager endpoints look like this:

https://www.linkedin.com/voyager/api/identity/profileView/tom-quirk

Or, more clearly

 ___________________________________ _______________________________
|             base path             |            resource           |
https://www.linkedin.com/voyager/api /identity/profileView/tom-quirk

They are authenticated with a simple cookie, which we send with every request, along with a bunch of headers.

To get a cookie, we POST a given username and password (of a valid Linkedin user account) to https://www.linkedin.com/uas/authenticate.

To find endpoints

We're looking at the Linkedin website and we spot some data we want. What now?

The most reliable method to find the relevant endpoint is to:

  1. view source

  2. command-f/search the page for some keyword in the data. This will exist inside of a <code> tag.

  3. Scroll down to the next adjacent element which will be another <code> tag, probably with an id that looks something like

    <code style="display: none" id="datalet-bpr-guid-3900675">
      {"request":"/voyager/api/identity/profiles/tom-quirk/profileView","status":200,"body":"bpr-guid-3900675"}
    </code>
  4. The value of request is the url! 🀘

You can also use the network tab in you browsers developer tools, but you will encounter mixed results.

How Clients query Voyager

linkedin.com queries data using the Rest-li Protocol. Rest-li is an internal query language/syntax where clients (like linkedin.com) to specify what data they want (similar to the GraphQL concept).

Here's an example of making a request for an organisation's name and groups (the Linkedin groups it manages):

/voyager/api/organization/companies?decoration=(name,groups*~(entityUrn,largeLogo,groupName,memberCount,websiteUrl,url))&q=universalName&universalName=linkedin

The "querying" happens in the decoration parameter, which looks like

(
    name,
    groups*~(entityUrn,largeLogo,groupName,memberCount,websiteUrl,url)
)

So here, we request an organisation name, and a list of groups, where for each group we want largeLogo, groupName, etc.

Different endpoints use different parameters (and perhaps even different syntaxes) to specify these queries. Notice that the above query had a parameter q whose value was universalName; the query was then specified with the decoration parameter.

In contrast, the /search/cluster endpoint uses q=guided, and specifies its query with the guided parameter, whose value is something like

List(v->PEOPLE)

It could be possible to document (and implement a nice interface for) this query language - as we add more endpoints to this project, I'm sure it will become more clear if such a thing would be possible (and if it's worth it).

Releasing a new version

  1. Bump version in __init__.py
  2. python3 setup.py sdist bdist_wheel
  3. python3 -m twine upload dist/*

More Repositories

1

realestate-com-au-api

🏠 Realestate.com.au API for Python
Python
103
star
2

brunch-vue-barebones

A Barebones Brunch Skeleton for Vue.js
JavaScript
54
star
3

etherfunk

πŸͺ© Your Ethereum Control Panel
TypeScript
24
star
4

messen

πŸ’¬ Rapidly build Facebook Messenger apps in Node.js
TypeScript
17
star
5

flatmates-api

🏠Python interface for flatmates.com.au
Python
9
star
6

FlickrBox

πŸ“Έ Backup photos to Flickr, just like Dropbox!
Python
7
star
7

uq-catalogue-api

πŸŽ“(Unofficial) API and webscraper for University of Queensland Course and Program Data
Python
6
star
8

fajita

🌯Quick Python wrappers for HTTP APIs
Python
5
star
9

forge-run-parser

extract contract addresses from forge deployments
TypeScript
5
star
10

photo-smurf

Efficient file organisation in Python
Python
5
star
11

threads-api

Threads by Instagram API for Python
4
star
12

next-juicebox

A Next.js template for building Juicebox apps
TypeScript
3
star
13

hugo-brutal

Brutalism-inspired theme for Hugo
CSS
3
star
14

linkedin-feed-eradicator

Hide your Linkedin feed so you can actually get sh*t done, instead of seeing "motivational" posts about getting sh*t done
CSS
3
star
15

photo-smurf-go

πŸ“· Batch Photo Library Cleanup in Go
Go
2
star
16

python-luminati

🌐 Python interface for Luminati
Python
2
star
17

seek-com-au-api

πŸ§‘β€πŸ’Ό Python wrapper for the Seek API
Python
2
star
18

awesome-climbing

collection of dope climbing tech tips/guides/tutorials
2
star
19

1word

A 1-Word Story Game in Node ft. Websockets and Vue.js
JavaScript
1
star
20

property-listing-training-data

Python
1
star
21

open-cg-keyboard

Piano Keyboard modelled in OpenGL using Python
Python
1
star
22

gitmail-core

βœ‰οΈgitmail.io core
JavaScript
1
star
23

py-midiminer

Mine MIDI data like a boss
Python
1
star
24

clickport-agent

⚑️ Expose internal scripts via a REST API (GitLab Mirror)
Go
1
star