social-app-django icon indicating copy to clipboard operation
social-app-django copied to clipboard

Getting profilePicture url from LinkedIn

Open allison9y opened this issue 5 years ago • 2 comments

Hope this is relevant here.

Trying to get the profile picture from LinkedIn but it returns the image urn as it states. Is there an easy way to extract the picture url using a pipeline?

allison9y avatar Aug 13 '19 08:08 allison9y

may i know the filename where this code reside

safwan20 avatar Dec 26 '19 13:12 safwan20

I accomplished getting the profilePicUrl with the following steps, bet there's a much straightforward solution but this worked for me:

# set linkedin_login
linkedin_login = request.user.social_auth.get(provider='linkedin-oauth2')
extra_data = linkedin_login.extra_data

# get access token
access_token = extra_data['access_token']

# set profilePicServiceUrl
profilePicServiceUrl = f"https://api.linkedin.com/v2/me?projection=(id,profilePicture(displayImage~:playableStreams))&oauth2_access_token={access_token}"

# get response
response = requests.get(profilePicServiceUrl).json()

# parse profilePicUrl
profilePicUrl = response['profilePicture']['displayImage~']['elements'][1]['identifiers'][0]['identifier']

mohapsat avatar Apr 02 '20 05:04 mohapsat