linkedin-api: Unofficial LinkedIn API Client

2.3.1 · active · verified Fri Apr 17

linkedin-api is an unofficial Python client for interacting with LinkedIn's internal APIs. It allows developers to programmatically access various LinkedIn features, such as profiles, connections, and company data, by simulating browser behavior. As it uses unofficial APIs, it is prone to breaking changes and requires careful usage to avoid account issues. The current version is 2.3.1, with releases occurring as needed to address LinkedIn's frequent changes.

Common errors

Warnings

Install

Imports

Quickstart

Initialize the Linkedin API client with your username and password, then make a simple call to retrieve a user profile. It's crucial to handle credentials securely, preferably via environment variables. This library uses unofficial APIs, so methods and responses might change without notice.

import os
from linkedin_api import Linkedin

# It's highly recommended to use environment variables for credentials
USERNAME = os.environ.get('LINKEDIN_USERNAME', 'your_email@example.com')
PASSWORD = os.environ.get('LINKEDIN_PASSWORD', 'your_strong_password')

if not USERNAME or not PASSWORD:
    print("Please set LINKEDIN_USERNAME and LINKEDIN_PASSWORD environment variables.")
else:
    try:
        api = Linkedin(USERNAME, PASSWORD)
        # Example: Get a public profile by its LinkedIn URL or ID
        # Replace 'ACoAAADm-wABuE77A8WbNlQoV-xT8D12345' with an actual profile ID
        profile = api.get_profile('ACoAAADm-wABuE77A8WbNlQoV-xT8D12345')
        print(f"Successfully fetched profile for {profile.get('firstName')} {profile.get('lastName')}")
        # Example: Get posts from a specific person
        # posts = api.get_profile_posts('ACoAAADm-wABuE77A8WbNlQoV-xT8D12345')
        # print(f"Fetched {len(posts)} posts.")

    except Exception as e:
        print(f"An error occurred: {e}")

view raw JSON →