Skip to main content

Introduction

The LinkedIn-API-JSON-Client library provides an abstract interface for working with the LinkedIn API. My goal is that you should not have to understand oauth or much of the details of the LinkedIn client library (if setup correctly, it should just work).

All functions and classes are documented inline. If you have additional questions, I can be reached on github or at admin@mattsnider.com.

Disclaimer

This package is loosely based on the LinkedIn-Client-Library by Aaron Brenzel. The original library was written for XML support, but LinkedIn now supports JSON responses, which IMHO provides a cleaner interface for use with python. I have tried to preserve the same general architecture and api functions, while adding some new ones, improving error management, and making the API more DRY.

Getting started

Standard stuff applies to install. Use PIP to install with dependencies:

pip install linkedin-api-json-client

Or install from the command line:

python setup.py install

If you install from the command line, you will need to also install the oauth2, simplejson, and httplib2 packages.

This package is intended for use with the LinkedIn API. You must supply your own API key for this library to work. Once you have an API key from LinkedIn, the syntax for instantiating an API client object is this:

my_key = 'mysecretkey'
my_secret = 'mysecretsecret'
li_client = LinkedInJsonAPI(my_key, my_secret)

From there, you can obtain request tokens, authorization urls, access tokens, and actual LinkedIn data through the LinkedInJsonAPI object’s methods. The object will handle signing requests, url formatting, and JSON parsing for you.

Dependencies

Currently, the API is dependent on oauth2, httplib2 (for oauth2), and simplejson. All can easily be obtained using Python Package Index, and will be automatically included, if you use PIP to install.

Authorization Guide

Oauth authorization is a multi-step process. When a user wants to authorize your app, you must first create an authorization URL, indicating which permissions your application needs, and redirect the user there:

from urllib import urlencode
from linkedin_json_client.constants import LinkedInScope
try:
    request_token_dict = li_client.get_request_token(scope=[
        LinkedInScope.BASIC_PROFILE, LinkedInScope.EMAIL_ADDRESS])
    url = '%s?%s' % (li_client.authorize_path, urlencode(request_token_dict))
    # store your request token in the user session for use in callback
    request.session['li_request_token'] = request_token_dict
    # REDIRECT USER TO url
except (HTTPError, socket.error):
    # failed to connect to LinkedIn, handle this in your application

When you setup your application on LinkedIn, you specified a callback URL for authorization. That URL should compare the stored request token against an oauth verifier token:

oauth_verifier = request.GET.get('oauth_verifier')
request_token = request.session.get('li_request_token')

oauth_problem = request.GET.get('oauth_problem')
if oauth_problem or request_token is None:
    if oauth_problem == 'user_refused':
        # user refused auth, handle in your application
    # some other problem, handle in your application
else:
    access_token = li_client.get_access_token(request_token, oauth_verifier)
    # user successfully authorized, store this access_token and associate with the user for use with API

Once you have an access token, you may make calls against the API:

from linkedin_json_client.constants import BasicProfileFields, BasicProfileSelectors
json_object = li_client.get_user_profile(access_token, [BasicProfileSelectors.FIRST_NAME, BasicProfileSelectors.LAST_NAME, BasicProfileSelectors.ID])

json_object[BasicProfileFields.ID]
json_object[BasicProfileFields.FIRST_NAME]
json_object[BasicProfileFields.LAST_NAME]

If something goes wrong with any API calls, except authorization, a LinkedInApiJsonClientError is raised, so it is best to always wrap API calls in a try statement and handle the error in your app:

try:
    # api call
except LinkedInApiJsonClientError, e:
    print e

Todo

  1. Search support

  2. Test coverage where the LinkedIn API is mocked

  3. Build docs from comments

  4. Test coverage against the LinkedIn API, will require test users with fairly complete profiles. Haven’t been able to get help from LinkedIn to create test data, so if anyone has any ideas here, let me know.

Metadata

Release files for linkedin-api-json-client 0.2.6

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for linkedin-api-json-client 0.2.6
File Size Uploaded
linkedin-api-json-client-0.2.6.tar.gz 13.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for linkedin-api-json-client 0.2.6
File Interpreter ABI Platform
linkedin-api-json-client-0.2.6.macosx-10.7-intel.exe Details

Total release size: 92.9 kB

Release files / linkedin-api-json-client-0.2.6.tar.gz

Download URL linkedin-api-json-client-0.2.6.tar.gz
Size 13.0 kB
Tags Source
SHA-256 checksum
How to use checksums
2f25541fc044283bf6e00ce85e064c4744886a74e12c81cc46bcff67d91834c1
BLAKE2b-256 checksum
How to use checksums
09553e9bb8293ed4fb7f316e6d5db47b553c331e011434d6ce15035b35746be4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / linkedin-api-json-client-0.2.6.macosx-10.7-intel.exe

Download URL linkedin-api-json-client-0.2.6.macosx-10.7-intel.exe
Size 79.9 kB
Tags Source
SHA-256 checksum
How to use checksums
4d7d2a8c8dfce1f9d94fd84dc7e1cc0b6f99675dce3531fdaff5926e38870539
BLAKE2b-256 checksum
How to use checksums
ca6321af9caa6fa1b1bf1dfe24aa6c495f4a89f7eb96112537e9b38b88db6722
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

0.2.6 This release

2 release files

0.2.5

2 release files

0.2.4

0.2.3

2 release files

0.2.2

2 release files

0.2.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page