diff --git a/README.md b/README.md index 63352f7..5df1310 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,6 @@ -# Overview +# LinkedIn API Python Client + +## Overview This library provides a thin Python client for making requests to LinkedIn APIs, utilizing the Python [requests](https://pypi.org/project/requests/) HTTP client library. LinkedIn's APIs are built on the [Rest.li](https://linkedin.github.io/rest.li/) framework with additional LinkedIn-specific constraints, which results in a robust yet complex protocol that can be challenging to implement correctly. @@ -6,18 +8,18 @@ This library helps reduce this complexity by formatting requests correctly, prov > :warning: This API client library is currently in beta and is subject to change. It may contain bugs, errors, or other issues that we are working to resolve. Use of this library is at your own risk. Please use caution when using it in production environments and be prepared for the possibility of unexpected behavior. We welcome any feedback or reports of issues that you may encounter while using this library. -## Features +### Features - Generic support for all Rest.li methods used in LinkedIn APIs - Supports Rest.li protocol version 2.0.0 - Provide interfaces for request options/response payloads - Built-in parameter encoding -- Utilities (e.g. URN handling, encoding/decoding) +- Utilities (e.g. URN handling, encoding) - Supports versioned APIs - Automatic query tunneling of requests - 2-legged and 3-legged OAuth2 support -## Table of Contents +### Table of Contents - [Requirements](#requirements) - [Installation](#installation) @@ -27,56 +29,56 @@ This library helps reduce this complexity by formatting requests correctly, prov - [Finder Request Example](#finder-request-example) - [More Examples](#more-examples) - [API Reference](#api-reference) - - [RestliClient](#restliclient) + - [RestliClient](#class-restliclient) - [Constructor](#constructor) - [Properties](#properties) - [Methods](#methods) - - [get()](#get-resource_path-access_token-path_keysnone-query_paramsnone-version_stringnone) - - [batch\_get()](#batch_get-resource_path-ids-access_token-path_keysnone-query_paramsnone-version_stringnone) - - [get\_all()](#get_all-resource_path-access_token-path_keysnone-query_paramsnone-version_stringnone) - - [finder()](#finder-resource_path-finder_name-access_token-path_keysnone-query_paramsnone-version_stringnone) - - [batch\_finder()](#batch_finder-resource_path-finder_name-finder_criteria-access_token-path_keysnone-query_paramsnone-version_stringnone) - - [create()](#create-resource_path-entity-access_token-path_keysnone-query_paramsnone-version_stringnone) - - [batch\_create()](#batch_create-resource_path-entities-access_token-path_keysnone-query_paramsnone-version_stringnone) - - [update()](#update-resource_path-entity-access_token-path_keysnone-query_paramsnone-version_stringnone) - - [batch\_update()](#batch_update-resource_path-ids-entities-access_token-path_keysnone-query_paramsnone-version_stringnone) - - [partial\_update()](#partial_updateresource_path-patch_set_object-access_token-path_keysnone-query_paramsnone-version_stringnone) - - [batch\_partial\_update()](#batch_partial_updateresource_path-ids-patch_set_objects-access_token-path_keysnone-query_paramsnone-version_stringnone) - - [delete()](#delete-resource_path-access_token-path_keysnone-query_paramsnone-version_stringnone) - - [batch\_delete()](#batch_delete-resource_path-ids-access_token-path_keysnone-query_paramsnone-version_stringnone) - - [action()](#action-resource_path-action_name-access_token-action_paramsnone-path_keysnone-query_paramsnone-version_stringnone) - - [AuthClient](#class-authclientclient_id-client_secret-redirect_urlnone) + - [`get()`](#get-resource_path-access_token-path_keysnone-query_paramsnone-version_stringnone) + - [`batch_get()`](#batch_get-resource_path-ids-access_token-path_keysnone-query_paramsnone-version_stringnone) + - [`get_all()`](#get_all-resource_path-access_token-path_keysnone-query_paramsnone-version_stringnone) + - [`finder()`](#finder-resource_path-finder_name-access_token-path_keysnone-query_paramsnone-version_stringnone) + - [`batch_finder()`](#batch_finder-resource_path-finder_name-finder_criteria-access_token-path_keysnone-query_paramsnone-version_stringnone) + - [`create()`](#create-resource_path-entity-access_token-path_keysnone-query_paramsnone-version_stringnone) + - [`batch_create()`](#batch_create-resource_path-entities-access_token-path_keysnone-query_paramsnone-version_stringnone) + - [`update()`](#update-resource_path-entity-access_token-path_keysnone-query_paramsnone-version_stringnone) + - [`batch_update()`](#batch_update-resource_path-ids-entities-access_token-path_keysnone-query_paramsnone-version_stringnone) + - [`partial_update()`](#partial_update-resource_path-patch_set_object-access_token-path_keysnone-query_paramsnone-version_stringnone) + - [`batch_partial_update()`](#batch_partial_update-resource_path-ids-patch_set_objects-access_token-path_keysnone-query_paramsnone-version_stringnone) + - [`delete()`](#delete-resource_path-access_token-path_keysnone-query_paramsnone-version_stringnone) + - [`batch_delete()`](#batch_delete-resource_path-ids-access_token-path_keysnone-query_paramsnone-version_stringnone) + - [`action()`](#action-resource_path-action_name-access_token-action_paramsnone-path_keysnone-query_paramsnone-version_stringnone) + - [AuthClient](#class-authclient) - [Constructor](#constructor-1) - [Properties](#properties-1) - [Methods](#methods-1) - - [generate\_member\_auth\_url()](#generate_member_auth_url-scopes-statenone) - - [exchange\_auth\_code\_for\_access\_token()](#exchange_auth_code_for_access_token-code) - - [exchange\_refresh\_token\_for\_access\_token()](#exchange_refresh_token_for_access_token-refresh_token) - - [get\_two\_legged\_access\_token()](#get_two_legged_access_token-) - - [introspect\_access\_token()](#introspect_access_token-access_token) + - [`generate_member_auth_url()`](#generate_member_auth_url-scopes-statenone) + - [`exchange_auth_code_for_access_token()`](#exchange_auth_code_for_access_token-code) + - [`exchange_refresh_token_for_access_token()`](#exchange_refresh_token_for_access_token-refresh_token) + - [`get_two_legged_access_token()`](#get_two_legged_access_token-) + - [`introspect_access_token()`](#introspect_access_token-access_token) - [List of dependencies](#list-of-dependencies) -# Requirements +## Requirements - Python >= 3.7 -# Installation +## Installation ```sh pip install linkedin-api-client ``` -# Getting Started +## Getting Started -## Pre-requisites +### Pre-requisites 1. Create or use an existing developer application from the [LinkedIn Developer Portal](https://www.linkedin.com/developers/apps/) 2. Request access to the Sign In With LinkedIn API product. This is a self-serve product that will be provisioned immediately to your application. 3. Generate a 3-legged access token using the Developer Portal [token generator tool](https://www.linkedin.com/developers/tools/oauth/token-generator), selecting the r_liteprofile scope. -## Simple API Request Example +### Simple API Request Example Here is an example of using the client to make a simple GET request to [fetch the current user's profile](https://learn.microsoft.com/en-us/linkedin/consumer/integrations/self-serve/sign-in-with-linkedin#retrieving-member-profiles). This requires a 3-legged access token with the "r_liteprofile" scope, which is included with the Sign In With LinkedIn API product. @@ -92,7 +94,7 @@ response = restli_client.get( print(response.entity) ``` -## Finder Request Example +### Finder Request Example Here is a more non-trivial example to [find ad accounts](https://learn.microsoft.com/en-us/linkedin/marketing/integrations/ads/account-structure/create-and-manage-accounts?#search-for-accounts) by some search critiera. This requires a 3-legged access token with the "r_ads" scope, which is included with the Advertising APIs product. @@ -123,20 +125,20 @@ response = restli_client.finder( ad_accounts = response.elements ``` -## More Examples +### More Examples There are more examples of using the client in [/examples](examples/) directory. -# API Reference +## API Reference -## class RestliClient() +### `class RestliClient` The Rest.li API client defines instance methods for all the Rest.li methods which are used by LinkedIn APIs. All calls are blocking. Rest.li defines a standard set of methods that can operate on a resource, each of which maps to an HTTP method. Depending on the resource, some Rest.li methods are not applicable or not implemented. Read the API docs to determine what Rest.li method is applicable and the relevant request parameters. -### Constructor +#### Constructor An instance of the API client must be created before using. This creates a session object that will be used for making all subsequent requests. @@ -152,15 +154,15 @@ The Requests library [session](https://requests.readthedocs.io/en/latest/user/ad restli_client.session.hooks = { 'response': [do_something_fn, do_something_2_fn] } ``` -### Properties +#### Properties | Property | Description | |---|---| | `session` | The session object used for making http requests. This is exposed to allow for additional configuration (e.g. adding custom request/response event hooks). | -### Methods +#### Methods -#### Base Request Parameters +##### Base Request Parameters All Rest.li request methods of the API client support the following request parameters: @@ -172,19 +174,19 @@ All Rest.li request methods of the API client support the following request para | `query_params` | Dict[str,Any] | No | A map of query parameters. The query parameter values (strings, lists, objects) will be correctly encoded by this method, so these should not be encoded. | | `version_string` | str | No | An optional version string of the format "YYYYMM" or "YYYYMM.RR". If specified, the version header will be passed and the request will use the versioned APIs base URL | -#### get *(resource_path, access_token, path_keys=None, query_params=None, version_string=None)* +##### `get (resource_path, access_token, path_keys=None, query_params=None, version_string=None)` Makes a Rest.li GET request to fetch the specified entity on a resource. This method will perform query tunneling if necessary. -***Parameters:*** +**Parameters:** This method only uses the [base request parameters](#base-request-parameters) defined above. -***Response:*** +**Return value:** Returns [GetResponse](#class-getresponse) object -***Example:*** +**Example:** ```python response = restli_client.get( @@ -198,11 +200,11 @@ ad_account = response.entity ``` -#### batch_get *(resource_path, ids, access_token, path_keys=None, query_params=None, version_string=None)* +##### `batch_get (resource_path, ids, access_token, path_keys=None, query_params=None, version_string=None)` Makes a Rest.li BATCH_GET request to fetch multiple entities on a resource. This method will perform query tunneling if necessary. -***Parameters:*** +**Parameters:** The additional parameters besides the [base request parameters](#base-request-parameters) are: @@ -210,12 +212,11 @@ The additional parameters besides the [base request parameters](#base-request-pa |---|---|---|---| | `ids` | List[Union[str,int,Dict[str,Any]]] | Yes | The list of entity ids to fetch on the resource. These will be encoded and added to the query parameters. | -***Response:*** +**Return value:** Returns a [BatchGetResponse](#class-batchgetresponse) object. - -***Example:*** +**Example:** ```python response = restli_client.batch_get( @@ -228,19 +229,19 @@ campaign_groups = response.results.items() ``` -#### get_all *(resource_path, access_token, path_keys=None, query_params=None, version_string=None)* +##### `get_all (resource_path, access_token, path_keys=None, query_params=None, version_string=None)` Makes a Rest.li GET_ALL request to fetch all entities on a resource. -***Parameters:*** +**Parameters:** This method only uses the [base request parameters](#base-request-parameters) defined above. -***Response:*** +**Return value:** Returns [CollectionResponse](#class-collectionresponse) object -***Example:*** +**Example:** ```python response = restli_client.get_all( @@ -256,11 +257,11 @@ fields_of_study = response.elements total = response.paging.total ``` -#### finder *(resource_path, finder_name, access_token, path_keys=None, query_params=None, version_string=None)* +##### `finder (resource_path, finder_name, access_token, path_keys=None, query_params=None, version_string=None)` Makes a Rest.li FINDER request to find entities by some specified criteria. -***Parameters:*** +**Parameters:** The additional parameters besides the [base request parameters](#base-request-parameters) are: @@ -268,11 +269,11 @@ The additional parameters besides the [base request parameters](#base-request-pa |---|---|---|---| | `finder_name` | str | Yes | The Rest.li finder name. This will be added to the request query parameters. | -***Response:*** +**Return value:** Returns a [CollectionResponse](#class-collectionresponse) object. -***Example:*** +**Example:** ```python response = restli_client.finder( @@ -298,11 +299,11 @@ ad_accounts = response.elements total = response.paging.total ``` -#### batch_finder *(resource_path, finder_name, finder_criteria, access_token, path_keys=None, query_params=None, version_string=None)* +##### `batch_finder (resource_path, finder_name, finder_criteria, access_token, path_keys=None, query_params=None, version_string=None)` Makes a Rest.li BATCH_FINDER request to find entities by multiple sets of criteria. -***Parameters:*** +**Parameters:** The additional parameters besides the [base request parameters](#base-request-parameters) are: @@ -311,11 +312,11 @@ The additional parameters besides the [base request parameters](#base-request-pa | `finder_name` | str | Yes | The Rest.li batch finder name (the value of the "bq" query parameter). This will be added to the request query parameters. | | `finder_criteria` | Tuple[str, List[Dict[str,Any]]] | Yes | The required batch finder criteria information. This is a tuple with the first value being the batch finder criteria parameter name. The second value is the list of finder param objects. The batch finder results are correspondingly ordered according to this list. The batch finder criteria will be encoded and added to the request query parameters. | -***Response:*** +**Return value:** Returns a [BatchFinderResponse](#class-batchfinderresponse) object. -***Example:*** +**Example:** ```python response = restli_client.batch_finder( @@ -341,11 +342,11 @@ admin_read_authorizations = response.results[0].elements organic_share_delete_authorizations = response.results[1].elements ``` -#### create *(resource_path, entity, access_token, path_keys=None, query_params=None, version_string=None)* +##### `create (resource_path, entity, access_token, path_keys=None, query_params=None, version_string=None)` Makes a Rest.li CREATE request to create a new resource entity. -***Parameters:*** +**Parameters:** The additional parameters besides the [base request parameters](#base-request-parameters) are: @@ -353,11 +354,11 @@ The additional parameters besides the [base request parameters](#base-request-pa |---|---|---|---| | `entity` | Dict[str,Any] | Yes | A dictionary representation of the entity to create | -***Response:*** +**Return value:** Returns a [CreateResponse](#class-createresponse) object. -***Example:*** +**Example:** ```python response = restli_client.create( @@ -372,11 +373,11 @@ response = restli_client.create( created_entity_id = response.entity_id ``` -#### batch_create *(resource_path, entities, access_token, path_keys=None, query_params=None, version_string=None)* +##### `batch_create (resource_path, entities, access_token, path_keys=None, query_params=None, version_string=None)` Makes a Rest.li BATCH_CREATE request to create multiple entities in a single call. -***Parameters:*** +**Parameters:** The additional parameters besides the [base request parameters](#base-request-parameters) are: @@ -384,11 +385,11 @@ The additional parameters besides the [base request parameters](#base-request-pa |---|---|---|---| | `entities` | List[Dict[str,Any]] | Yes | A list of entities to create | -***Response:*** +**Return value:** Returns a [BatchCreateResponse](#class-batchcreateresponse) object. -***Example:*** +**Example:** ```python response = restli_client.batch_create( @@ -412,11 +413,11 @@ created_elements = response.elements first_created_element_id = response.elements[0].id ``` -#### update *(resource_path, entity, access_token, path_keys=None, query_params=None, version_string=None)* +##### `update (resource_path, entity, access_token, path_keys=None, query_params=None, version_string=None)` Makes a Rest.li UPDATE request to update an entity (overwriting the entity with the provided value). -***Parameters:*** +**Parameters:** The additional parameters besides the [base request parameters](#base-request-parameters) are: @@ -424,11 +425,11 @@ The additional parameters besides the [base request parameters](#base-request-pa |---|---|---|---| | `entity` | Dict[str,Any] | Yes | The value of the updated entity. This will completely overwrite the entity. | -***Response:*** +**Return value:** Returns a [UpdateResponse](#class-updateresponse) object. -***Example:*** +**Example:** ```python response = restli_client.update( @@ -450,11 +451,11 @@ response = restli_client.update( status = response.status_code ``` -#### batch_update *(resource_path, ids, entities, access_token, path_keys=None, query_params=None, version_string=None)* +##### `batch_update (resource_path, ids, entities, access_token, path_keys=None, query_params=None, version_string=None)` Makes a Rest.li BATCH_UPDATE request to update multiple entities in a single call. -***Parameters:*** +**Parameters:** The additional parameters besides the [base request parameters](#base-request-parameters) are: @@ -463,11 +464,11 @@ The additional parameters besides the [base request parameters](#base-request-pa | `ids` | List[Union[str,int,Dict[str,Any]]] | Yes | The ids of the entities to update | | `entities` | List[Dict[str,Any]] | Yes | The values to update the specified entities to. This should be the same order as the `ids` argument. | -***Response:*** +**Return value:** Returns a [BatchUpdateResponse](#class-batchupdateresponse) object. -***Example:*** +**Example:** ```python response = restli_client.batch_update( @@ -486,13 +487,13 @@ response = restli_client.batch_update( batch_results = response.results.items() ``` -#### *partial_update(resource_path, patch_set_object, access_token, path_keys=None, query_params=None, version_string=None)* +##### `partial_update (resource_path, patch_set_object, access_token, path_keys=None, query_params=None, version_string=None)` Makes a Rest.li PARTIAL_UPDATE request to update part of an entity. Directly specify the patch object to send in the request. Note: While the Rest.li protocol supports very granular patch objects with setting and deletion of nested properties, most LinkedIn APIs only support partial update on the top-level fields of an entity. -***Parameters:*** +**Parameters:** The additional parameters besides the [base request parameters](#base-request-parameters) are: @@ -500,11 +501,11 @@ The additional parameters besides the [base request parameters](#base-request-pa |---|---|---|---| | `patch_set_object` | Dict[str,Any] | Yes | The value of the entity with only the modified fields present. This will be sent directly in the request body as `patch: { $set: patch_set_object }`. | -***Response:*** +**Return value:** Returns a [UpdateResponse](#class-updateresponse) object. -***Example:*** +**Example:** ```python response = restli_client.partial_update( @@ -520,11 +521,11 @@ response = restli_client.partial_update( status = response.status_code ``` -#### *batch_partial_update(resource_path, ids, patch_set_objects, access_token, path_keys=None, query_params=None, version_string=None)* +##### `batch_partial_update (resource_path, ids, patch_set_objects, access_token, path_keys=None, query_params=None, version_string=None)` Makes a Rest.li BATCH_PARTIAL_UPDATE request to update multiple entities at once, by only providing the fields of the entities that require updating. -***Parameters:*** +**Parameters:** The additional parameters besides the [base request parameters](#base-request-parameters) are: @@ -533,11 +534,11 @@ The additional parameters besides the [base request parameters](#base-request-pa | `ids` | List[Union[str,int,Dict[str,Any]]] | Yes | The list of entity ids to update. These will be encoded and added to the query parameters. | | `patch_set_objects` | List[Dict[str,Any]] | Yes | The list of entity values, represented as a dictionary, with only the modified fields present. | -***Response:*** +**Return value:** Returns a [BatchUpdateResponse](#class-batchupdateresponse) object. -***Example:*** +**Example:** ```python response = restli_client.batch_partial_update( @@ -558,19 +559,19 @@ response = restli_client.batch_partial_update( result_status = response.results["123"].status ``` -#### delete *(resource_path, access_token, path_keys=None, query_params=None, version_string=None)* +##### `delete (resource_path, access_token, path_keys=None, query_params=None, version_string=None)` Makes a Rest.li DELETE request to delete an entity. -***Parameters:*** +**Parameters:** This method only uses the [base request parameters](#base-request-parameters) defined above. -***Response:*** +**Return value:** Returns [BaseRestliResponse](#class-baserestliresponse) object -***Example:*** +**Example:** ```python response = restli_client.delete( @@ -582,11 +583,11 @@ response = restli_client.delete( status_code = response.status_code ``` -#### batch_delete *(resource_path, ids, access_token, path_keys=None, query_params=None, version_string=None)* +##### `batch_delete (resource_path, ids, access_token, path_keys=None, query_params=None, version_string=None)` Makes a Rest.li BATCH_DELETE request to delete multiple entities at once. -***Parameters:*** +**Parameters:** The additional parameters besides the [base request parameters](#base-request-parameters) are: @@ -594,11 +595,11 @@ The additional parameters besides the [base request parameters](#base-request-pa |---|---|---|---| | `ids` | List[Union[str,int,Dict[str,Any]]] | Yes | The list of entity ids to delete. These will be encoded and added to the query parameters. | -***Response:*** +**Return value:** Returns [BatchDeleteResponse](#class-batchdeleteresponse) object -***Example:*** +**Example:** ```python response = restli_client.batch_delete( @@ -610,11 +611,11 @@ response = restli_client.batch_delete( status_code = response.results["123"].status ``` -#### action *(resource_path, action_name, access_token, action_params=None, path_keys=None, query_params=None, version_string=None)* +##### `action (resource_path, action_name, access_token, action_params=None, path_keys=None, query_params=None, version_string=None)` Makes a Rest.li ACTION request to perform an action on a specified resource. This method is flexible and generally used when the action does not fit within the standard behavior defined by the other Rest.li methods. -***Parameters:*** +**Parameters:** The additional parameters besides the [base request parameters](#base-request-parameters) are: @@ -623,11 +624,11 @@ The additional parameters besides the [base request parameters](#base-request-pa | `action_name` | str | Yes | The action method name. This will be added to the query parameters. | | `action_params` | Dict[str,Any] | No | An optional map of action parameters and their values. This will be sent in the request body. | -***Response:*** +**Return value:** Returns [ActionResponse](#class-actionresponse) object -***Example:*** +**Example:** ```python response = restli_client.action( @@ -645,9 +646,9 @@ response = restli_client.action( status_code = response.status_code ``` -### Response Classes +#### Response Classes -#### *class BaseRestliResponse()* +##### `class BaseRestliResponse` All Rest.li request methods of the API client return a response object subclassed from BaseRestliResponse, containing standard response data, along with the original, raw response object. @@ -658,7 +659,7 @@ All Rest.li request methods of the API client return a response object subclasse | `headers` | CaseInsensitiveDict | A case-insensitive dictionary of response headers | | `response` | Response | The raw requests.Response object | -#### *class Paging()* +##### `class Paging` Paging metadata class @@ -668,7 +669,7 @@ Paging metadata class | count | int | The number of results returned in the response | | total | int | The total number of results available | -#### *class GetResponse()* +##### `class GetResponse` Base class: [BaseRestliResponse](#class-baserestliresponse) @@ -676,7 +677,7 @@ Base class: [BaseRestliResponse](#class-baserestliresponse) |---|---|---| | `entity` | Union[Dict[str,Any], str, int, bool] | The representation (typically a dictionary) of the retrieved entity, decoded from the json-encoded response content | -#### *class BatchGetResponse()* +##### `class BatchGetResponse` Base class: [BaseRestliResponse](#class-baserestliresponse) @@ -686,7 +687,7 @@ Base class: [BaseRestliResponse](#class-baserestliresponse) | `statuses` | Dict[str,int] | A map of entities and status code, with the key being the encoded entity id, and the value being the status code number value. | | `errors` | Dict[str,Any] | A map containing entities that could not be successfully fetched, with the key being the encoded entity id, and the value being the error response. | -#### *class CollectionResponse()* +##### `class CollectionResponse` Base class: [BaseRestliResponse](#class-baserestliresponse) @@ -696,7 +697,7 @@ Base class: [BaseRestliResponse](#class-baserestliresponse) | `paging` | [Paging](#class-paging) | Optional paging metadata object | | `metadata` | Any | Optional response metadata object | -#### *class BatchFinderResponse()* +##### `class BatchFinderResponse` Base class: [BaseRestliResponse](#class-baserestliresponse) @@ -704,7 +705,7 @@ Base class: [BaseRestliResponse](#class-baserestliresponse) |---|---|---| | `results` | List[[BatchFinderResult](#class-batchfinderresult)] | The list of finder results, in the same order as the requested batch finder search criteria list | -#### *class BatchFinderResult()* +##### `class BatchFinderResult` | Properties | Type | Description | |---|---|---| @@ -714,7 +715,7 @@ Base class: [BaseRestliResponse](#class-baserestliresponse) | `error` | Any | Optional error details if finder call failed | | `isError` | bool | Flag if this finder call experienced an error | -#### *class CreateResponse()* +##### `class CreateResponse` Base class: [BaseRestliResponse](#class-baserestliresponse) @@ -723,7 +724,7 @@ Base class: [BaseRestliResponse](#class-baserestliresponse) | `entity_id` | str | The encoded entity id | | `entity` | Dict[str,Any] | Optional created entity. Some APIs support returning the created entity to eliminate the need for a subsequent GET call. | -#### *class BatchCreateResponse()* +##### `class BatchCreateResponse` Base class: [BaseRestliResponse](#class-baserestliresponse) @@ -731,7 +732,7 @@ Base class: [BaseRestliResponse](#class-baserestliresponse) |---|---|---| | `elements` | List[[BatchCreateResult](#class-batchcreateresult)] | The list of batch create results, corresponding to the order of the `entities` request parameter | -#### *class BatchCreateResult()* +##### `class BatchCreateResult` | Properties | Type | Description | |---|---|---| @@ -739,7 +740,7 @@ Base class: [BaseRestliResponse](#class-baserestliresponse) | `id` | str | The id of the created entity | | `error` | Any | Error details if the create call experienced an error | -#### *class UpdateResponse()* +##### `class UpdateResponse` Base class: [BaseRestliResponse](#class-baserestliresponse) @@ -747,7 +748,7 @@ Base class: [BaseRestliResponse](#class-baserestliresponse) |---|---|---| | `entity` | Dict[str,Any] | Optional entity after the update. Some APIs support returning the updated entity to eliminate the need for a subsequent GET call. | -#### *class BatchUpdateResponse()* +##### `class BatchUpdateResponse` Base class: [BaseRestliResponse](#class-baserestliresponse) @@ -755,13 +756,13 @@ Base class: [BaseRestliResponse](#class-baserestliresponse) |---|---|---| | `results` | Dict[str,[BatchUpdateResult](#class-batchupdateresult)] | The results map where the keys are the encoded entity ids, and the values are the individual update call results, which includes the status code. | -#### *class BatchUpdateResult()* +##### `class BatchUpdateResult` | Properties | Type | Description | |---|---|---| | `status` | int | The status code of the individual update call | -#### *class BatchDeleteResponse()* +##### `class BatchDeleteResponse` Base class: [BaseRestliResponse](#class-baserestliresponse) @@ -769,13 +770,13 @@ Base class: [BaseRestliResponse](#class-baserestliresponse) |---|---|---| | `results` | Dict[str,[BatchDeleteResult](#class-batchdeleteresult)] | The results map where the keys are the encoded entity ids, and the values are the individual delete call results, which includes the status code. | -#### *class BatchDeleteResult()* +##### `class BatchDeleteResult` | Properties | Type | Description | |---|---|---| | `status` | int | The status code of the delete call | -#### *class ActionResponse()* +##### `class ActionResponse` Base class: [BaseRestliResponse](#class-baserestliresponse) @@ -784,11 +785,11 @@ Base class: [BaseRestliResponse](#class-baserestliresponse) | `value` | Any | The action response value | -## class AuthClient(client_id, client_secret, redirect_url=None) +### `class AuthClient` While we recommend using any of several popular, open-source libraries for robustly managing OAuth 2.0 authentication, we provide a basic Auth Client as a convenience for testing APIs and getting started. -### Constructor +#### Constructor ```python from linkedin_api.clients.auth.client import AuthClient @@ -802,78 +803,87 @@ auth_client = AuthClient(client_id=MY_CLIENT_ID, client_secret=MY_CLIENT_SECRET, | `client_secret` | str | Yes | Client secret of your developer application. This can be found on your application auth settings page in the Developer Portal. | | `redirect_url` | str | No | If your integration will be using the authorization code flow to obtain 3-legged access tokens, this should be provided. This redirect URL must match one of the redirect URLs configured in the app auth settings page in the Developer Portal. | -### Properties +#### Properties | Property | Description | |---|---| | `session` | The session object used for making http requests. This is exposed to allow for additional configuration (e.g. adding custom request/response event hooks). | -### Methods +#### Methods -#### generate_member_auth_url *(scopes, state=None)* +##### `generate_member_auth_url (scopes, state=None)` Generates the member authorization URL to direct members to. Once redirected, the member will be presented with LinkedIn's OAuth consent page showing the OAuth scopes your application is requesting on behalf of the user. -***Parameters:*** +**Parameters:** | Parameter | Type | Required? | Description | |---|---|---|---| | `scopes` | List[str] | Yes | An array of OAuth scopes (3-legged member permissions) your application is requesting on behalf of the user. | | `state` | str | No | An optional string that can be provided to test against CSRF attacks. | -**Returns** the member authorization URL +**Return value:** + +The member authorization URL string -#### exchange_auth_code_for_access_token *(code)* +##### `exchange_auth_code_for_access_token (code)` Exchanges an authorization code for a 3-legged access token. After member authorization, the browser redirects to the provided redirect URL, setting the authorization code on the `code` query parameter. -***Parameters:*** +**Parameters:** | Parameter | Type | Required? | Description | |---|---|---|---| | `code` | str | Yes | The authorization code to exchange for an access token | -**Returns** an [AccessToken3LResponse](#class-accesstoken3lresponse) +**Return value:** -#### exchange_refresh_token_for_access_token *(refresh_token)* +Returns an [AccessToken3LResponse](#class-accesstoken3lresponse) object + +##### `exchange_refresh_token_for_access_token (refresh_token)` Exchanges a refresh token for a new 3-legged access token. This allows access tokens to be refreshed without having the member reauthorize your application. -***Parameters:*** +**Parameters:** | Parameter | Type | Required? | Description | |---|---|---|---| | `refresh_token` | str | Yes | The authorization code to exchange for an access token | -**Returns** an [RefreshTokenExchangeResponse](#class-refreshtokenexchangeresponse) +**Return value:** + +Returns a [RefreshTokenExchangeResponse](#class-refreshtokenexchangeresponse) object -#### get_two_legged_access_token *()* +##### `get_two_legged_access_token ()` Use client credential flow (2-legged OAuth) to retrieve a 2-legged access token for accessing APIs that are not member-specific. Developer applications do not have the client credential flow enabled by default. -***Parameters:*** +**Parameters:** None -**Returns** [AccessToken2LResponse](#class-accesstoken2lresponse) +**Return value:** + +Returns an [AccessToken2LResponse](#class-accesstoken2lresponse) object -#### introspect_access_token *(access_token)* +##### `introspect_access_token (access_token)` Introspect a 2-legged, 3-legged or Enterprise access token to get information on status, expiry, and other details. -***Parameters:*** +**Parameters:** | Parameter | Type | Required? | Description | |---|---|---|---| | `access_token` | str | Yes | A 2-legged, 3-legged or Enterprise access token. | -**Returns** [IntrospectTokenResponse](#class-introspecttokenresponse) +**Return value:** +Returns an [IntrospectTokenResponse](#class-introspecttokenresponse) object -### Response Classes +#### Response Classes -#### *class BaseAuthResponse()* +##### `class BaseAuthResponse` All request methods of the AuthClient return a response object subclassed from BaseAuthResponse, containing standard response data, along with the original, raw response object. @@ -884,7 +894,7 @@ All request methods of the AuthClient return a response object subclassed from B | `headers` | CaseInsensitiveDict | A case-insensitive dictionary of response headers | | `response` | Response | The raw requests.Response object | -#### *class AccessToken3LResponse()* +##### `class AccessToken3LResponse` Base class: [BaseAuthResponse](#class-baseauthresponse) @@ -896,7 +906,7 @@ Base class: [BaseAuthResponse](#class-baseauthresponse) | `refresh_token_expires_in` | Number | The TTL of the refresh token, in seconds. This is only present if refresh tokens are enabled for the application. | | `scope` | str | A comma-separated list of scopes authorized by the member (e.g. "r_liteprofile,r_ads") | -#### *class AccessToken2LResponse()* +##### `class AccessToken2LResponse` Base class: [BaseAuthResponse](#class-baseauthresponse) @@ -905,7 +915,7 @@ Base class: [BaseAuthResponse](#class-baseauthresponse) | `access_token` | str | The 2-legged access token | | `expires_in` | int | The TTL of the access token, in seconds | -#### *class RefreshTokenExchangeResponse()* +##### `class RefreshTokenExchangeResponse` Base class: [BaseAuthResponse](#class-baseauthresponse) @@ -917,7 +927,7 @@ Base class: [BaseAuthResponse](#class-baseauthresponse) | `refresh_token_expires_in` | Number | The TTL of the refresh token, in seconds. This is only present if refresh tokens are enabled for the application. | -#### *class IntrospectTokenResponse()* +##### `class IntrospectTokenResponse` Base class: [BaseAuthResponse](#class-baseauthresponse) @@ -934,7 +944,7 @@ Base class: [BaseAuthResponse](#class-baseauthresponse) --- -# List of dependencies +## List of dependencies The following table is a list of production dependencies.