diff --git a/README.md b/README.md index 1f9db47..e69a296 100644 --- a/README.md +++ b/README.md @@ -202,6 +202,39 @@ application.get_connections(totals_only=True) } ``` +## Sign In With LinkedIn (lite profile) + +Apps without access to full profile granted by LinkedIn are limited to the sign in with LinkedIn API, check out the [documentation](https://docs.microsoft.com/en-us/linkedin/consumer/integrations/self-serve/sign-in-with-linkedin). Requests to the profile API made by these apps are limited to the lite profile scope, check the [documentation](https://docs.microsoft.com/en-us/linkedin/shared/references/v2/profile/lite-profile?context=linkedin/consumer/context) for more details. + +To authenticate with this mode you need to pass the correct permissions to `LinkedInAuthentication`: + +```python +from linkedin_v2.linkedin import PERMISSIONS + +authentication = linkedin.LinkedInAuthentication(API_KEY, API_SECRET, RETURN_URL, [PERMISSIONS.LITE_PROFILE, PERMISSIONS.EMAIL_ADDRESS]) +``` + +With these permissions, `get_profile` returns only the profile's id, first name, and last name. It is possible to retrieve the profile picture by passing a specific projection to `get_profile`. + +```python +from linkedin_v2.linkedin import PROJECTIONS + +application.get_profile(params=PROJECTIONS.EXPAND_PROFILE_PICTURE) +# Be aware that expanding profile pcture results in a very large response json... +``` + +In order to fetch the profile's email, an extra call is required: + +```python +application.get_email() +{ + "handle": "urn:li:emailAddress:3775708763", + "handle~": { + "emailAddress": "hsimpson@linkedin.com" + } +} +``` + ## Throttle Limits LinkedIn API keys are throttled by default. You should take a look at the [Throttle Limits Documentation](http://developer.linkedin.com/documents/throttle-limits) to get more information about it. diff --git a/linkedin_v2/__init__.py b/linkedin_v2/__init__.py index c434301..fb1bba6 100644 --- a/linkedin_v2/__init__.py +++ b/linkedin_v2/__init__.py @@ -1,2 +1,2 @@ -__version__ = '0.9.5' +__version__ = '0.9.6' VERSION = tuple(map(int, __version__.split('.'))) diff --git a/linkedin_v2/linkedin.py b/linkedin_v2/linkedin.py index 40e1590..1f2c8d2 100644 --- a/linkedin_v2/linkedin.py +++ b/linkedin_v2/linkedin.py @@ -20,6 +20,7 @@ PERMISSIONS = enum('Permission', COMPANY_ADMIN='rw_company_admin', + LITE_PROFILE='r_liteprofile', BASIC_PROFILE='r_basicprofile', FULL_PROFILE='r_fullprofile', EMAIL_ADDRESS='r_emailaddress', @@ -53,6 +54,10 @@ SHARED='SHAR', VIRAL='VIRL') +PROJECTIONS = enum('Projection', + EXPAND_PROFILE_PICTURE={'projection': '(id,firstName,lastName,profilePicture(displayImage~:playableStreams))'}, + EXPAND_EMAIL={'q': 'members', 'projection': '(elements*(handle~))'}) + class LinkedInDeveloperAuthentication(object): """ @@ -77,8 +82,8 @@ class LinkedInAuthentication(object): Implements a standard OAuth 2.0 flow that involves redirection for users to authorize the application to access account data. """ - AUTHORIZATION_URL = 'https://www.linkedin.com/uas/oauth2/authorization' - ACCESS_TOKEN_URL = 'https://www.linkedin.com/uas/oauth2/accessToken' + AUTHORIZATION_URL = 'https://www.linkedin.com/oauth/v2/authorization' + ACCESS_TOKEN_URL = 'https://www.linkedin.com/oauth/v2/accessToken' def __init__(self, key, secret, redirect_uri, permissions=None): self.key = key @@ -194,3 +199,9 @@ def get_profile(self, member_id=None, member_url=None, selectors=None, json_response = response.json() json_response.update({'numConnections': connections}) return json_response + + def get_email(self): + url = '%s/emailAddress' % ENDPOINTS.BASE + response = self.make_request('GET', url, params=PROJECTIONS.EXPAND_EMAIL) + raise_for_error(response) + return response.json()