Reputation: 59
I know that this should be a question, but after such a headache, I thought that I should help some one with this same problem.
I'm using Allauth 0.42.0 and Django 3.0.8, following the allauth documentation, I could not, for the love of my life get the Profile Picture url from the user.
Upvotes: 1
Views: 496
Reputation: 59
But hours of searching lead me to this solution:
# access_token required by LinkedIn's API
access_token = SocialToken.objects.get(account__user=user, account__provider='linkedin_oauth2')
# The request
r = requests.get(f"https://api.linkedin.com/v2/me?projection=(profilePicture("
f"displayImage~:playableStreams))&oauth2_access_token={access_token}")
# The json on the profile picture key
profile_pic_json = r.json().get('profilePicture')
# There's a lot of pictures sizes, so I put it on a array to easier reading
elements = profile_pic_json['displayImage~']['elements']
# elements[len(elements)-1] returns the pic with the highest resolution
# ['identifiers'][0]['identifier'] is the url itself
url_picture = elements[len(elements)-1]['identifiers'][0]['identifier']
I hope that this help someone.
Upvotes: 2