Получение профиля Linkedin Изображение профиля django -allauth - PullRequest
0 голосов
/ 04 августа 2020

Я знаю, что это должен быть вопрос, но после такой головной боли я подумал, что должен помочь кому-нибудь с этой же проблемой.

Я использую Allauth 0.42.0 и Django 3.0 .8, следуя документации allauth, я не мог, из любви к моей жизни, получить URL-адрес изображения профиля от пользователя.

1 Ответ

0 голосов
/ 04 августа 2020

Но часы поиска привели меня к этому решению:

# 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']

Я надеюсь, что это кому-то поможет.

...