social-app-django
social-app-django copied to clipboard
Getting profilePicture url from LinkedIn
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?
may i know the filename where this code reside
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']