Registry / communication / linkedin-api-client

linkedin-api-client

JSON →
library0.3.0pypypi✓ verified 22d ago

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.

pip install linkedin-api-client
INSTALL
IMPORT
SIG · LINKEDIN-API-CLIEN
L
linkedin-api-client
communicationpythonv0.3.0
Install
2.2s avg
Import
368ms
Disk
20MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.3.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.380s · 21.5MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 2.2s · import 0.356s · 22MB
20MB installed
● package 20MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

RestliClient
from linkedin_api.clients.restli.client import RestliClient
AuthClient
from linkedin_api.clients.auth.auth_client import AuthClient
Linkedin
from linkedin_api.clients.restli.client import RestliClient
from linkedin_api import Linkedin
The `Linkedin` class from `linkedin_api` (lowercase) refers to a popular, unofficial library that is *not* this official client. Using the unofficial library may violate LinkedIn's Terms of Service.

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}")
Debug
Known issues
betaThis API client library is officially in beta and is subject to change. It may contain bugs, errors, or other issues. Use in production environments should be approached with caution, and users should be prepared for unexpected behavior.
fix
Monitor official GitHub releases and documentation for updates and stability improvements. Implement robust error handling and fallback mechanisms in production applications.
affects: 0.1.0 - 0.3.0
gotchaThere are multiple Python libraries for LinkedIn, including a popular unofficial one (`linkedin-api` by Tom Quirk) that uses web scraping/simulation. This official `linkedin-api-client` library requires proper OAuth2 authentication and interaction via the LinkedIn Developer Portal, while the unofficial one may work by using a username/password, potentially violating LinkedIn's Terms of Service.
fix
Always verify the import path (`from linkedin_api.clients.restli.client import RestliClient`) to ensure you are using the official client. Consult the official GitHub repository for this library.
affects: All versions
breakingLinkedIn's underlying APIs are frequently updated with monthly versions, and these can introduce breaking changes (e.g., changes to resource paths, required fields, or deprecation of features). The client library aims to abstract some of this, but direct API calls may still be affected.
fix
Regularly consult the LinkedIn Developer documentation for API versioning and breaking changes. Test your integration thoroughly when new API versions are released or when updating the client library. Specify API versions in your requests where possible if the client supports it.
affects: All versions (due to upstream API changes)
gotchaAuthentication for the official LinkedIn API client relies on OAuth2 flows (2-legged for applications, 3-legged for user-specific actions). Obtaining valid access tokens (especially 3-legged) requires a pre-requisite setup in the LinkedIn Developer Portal, including creating an application, requesting API product access, and configuring redirect URIs.
fix
Familiarize yourself with the LinkedIn OAuth2 documentation. Ensure your LinkedIn application is correctly configured with necessary scopes and redirect URIs. For 3-legged auth, users must authorize your application in a web browser to get an authorization code, which is then exchanged for an access token.
affects: All versions
gotchaSome GitHub issues indicate that pagination may be broken with certain API versions, particularly for cursor-based pagination.
fix
Check the GitHub Issues for `linkedin-api-python-client` for specific workarounds or fixes related to pagination. Implement custom pagination logic if the built-in methods are not functioning as expected for your target API endpoints.
affects: Potentially 0.1.0 - 0.3.0 (depending on API version used)
Errors
Common errors & fixes
{"serviceErrorCode": 65600, "message": "Invalid access token", "status": 401}
This error occurs when the access token used in the API request is expired, revoked, malformed, or was never valid to begin with.
fix
Ensure you are using a currently valid access token obtained through the correct OAuth 2.0 flow. If the token is expired, refresh it using the refresh token; if the refresh token is also invalid, re-authenticate the user to obtain new tokens.
{"serviceErrorCode": 100, "message": "Not enough permissions to access: GET /me", "status": 403}
This '403 Access Denied' error indicates that your application does not have the necessary permissions (scopes) approved in the LinkedIn Developer Portal to access the requested API endpoint or data, or that your OAuth 2.0 implementation has issues like mismatched redirect URIs.
fix
Verify that your application has been granted all required API permissions in the LinkedIn Developer Portal, that the correct scopes are requested during the OAuth 2.0 authorization flow, and ensure your redirect_uri exactly matches the one configured in your app settings. For advanced data, you may need to join a LinkedIn Partner Program.
{"error": "invalid_grant", "error_description": "Token has been expired or revoked."}
This error typically occurs when attempting to exchange a refresh token for a new access token, but the refresh token is no longer valid because it has expired (LinkedIn refresh tokens have a fixed one-year lifetime), the user or an administrator revoked the app's access, or the app's permissions were changed.
fix
This is a token lifecycle problem; the only solution is to re-authenticate the user to obtain a new authorization code, which can then be exchanged for a new access token and refresh token. Ensure your application saves the most recent refresh token and handles token refresh proactively.
This resource is no longer available under v1 APIs
This error, often accompanied by a '410 Gone' HTTP status, means your application is trying to access an old LinkedIn API endpoint that has been deprecated and removed, as LinkedIn transitioned from v1 to v2 (and later versions) of its API.
fix
Update your API request URLs and parameters to use the current LinkedIn API version (e.g., v2 or /rest endpoints), referring to the latest LinkedIn API documentation for the correct endpoints and data formats.
{"error": "invalid_client", "error_description": "Client authentication failed"}
This error arises during the OAuth 2.0 token exchange when the client ID or client secret provided by your application is incorrect, or the request format (e.g., `Content-Type`) for the token exchange is improperly set.
fix
Double-check your `client_id` and `client_secret` values against those registered in your LinkedIn Developer Portal application. Ensure that the POST request for the token exchange includes `Content-Type: application/x-www-form-urlencoded` in the headers and sends `grant_type`, `client_id`, and `client_secret` in the request body.
Upgrade
Version history
0.3.0latest on PyPI · released Jun 29, 2023
Audit
Dependencies

No dependency data recorded yet.

Agent activity
39 hits · last 30 days
node
34
OpenAI (training)
1
Resources
linkedin-api-client — pip install linkedin-api-client · libregistry