LinkedIn API Python Client

0.3.0 · active · verified Sun Apr 12

The official Python client library for LinkedIn APIs. It provides a thin client for making requests to LinkedIn APIs, handling the complexities of the Rest.li framework, formatting requests, and managing authentication (OAuth2). The library aims to reduce the difficulty of interacting with LinkedIn's robust but complex API protocol. The current version is 0.3.0, and it maintains an active release cadence.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to make a simple GET request to the `/userinfo` endpoint using the `RestliClient`. It requires a 3-legged access token with appropriate scopes (e.g., `openid`, `profile`) obtained from the LinkedIn Developer Portal. Ensure you replace `YOUR_ACCESS_TOKEN_HERE` with a valid token or set the `LINKEDIN_ACCESS_TOKEN` environment variable.

import os
from linkedin_api.clients.restli.client import RestliClient

# Get your 3-legged access token from environment variables or a secure store.
# This token must be generated via the LinkedIn Developer Portal's OAuth 2.0 flow.
ACCESS_TOKEN = os.environ.get('LINKEDIN_ACCESS_TOKEN', 'YOUR_ACCESS_TOKEN_HERE')

if not ACCESS_TOKEN or ACCESS_TOKEN == 'YOUR_ACCESS_TOKEN_HERE':
    raise ValueError("Please set the LINKEDIN_ACCESS_TOKEN environment variable or replace the placeholder.")

restli_client = RestliClient()

try:
    # Example: Fetch current user's information
    response = restli_client.get(
        resource_path="/userinfo",
        access_token=ACCESS_TOKEN
    )
    print("Successfully fetched user info:")
    print(response.entity)
except Exception as e:
    print(f"An error occurred: {e}")

view raw JSON →