I have set up Facebook provide via django-allauth
. I want to change default extracted data. By default it's ['email', 'username', 'first_name', 'last_name', 'name']
. I also need user's birthday
and his profile photo
.
I have tried to override DefaultSocialAccountAdapter
, but I didn't find there useful methods.
Also I tried to set:
SOCIALACCOUNT_PROVIDERS = {
'facebook': {
'FIELDS': [
'id',
'email',
'name',
'birthday',
'locale',
'timezone',
'gender',
],
}
}
But nothing happend.
class SocialAccountAdapter(DefaultSocialAccountAdapter):
def populate_user(self,
request,
sociallogin,
data):
print(data)
super().populate_user(request, sociallogin, data)
data
still returns only 5 default fields
UPDATED WITH SOLUTION
from allauth.socialaccount.signals import pre_social_login
from django.dispatch import receiver
from datetime import datetime
@receiver(pre_social_login)
def populate_profile(request, sociallogin, **kwargs):
if sociallogin.account.provider == "facebook":
extra_data = sociallogin.account.extra_data
sociallogin.user.birth_date = datetime.strptime(extra_data['birthday'], '%m/%d/%Y').date()
sociallogin.user.full_name = extra_data['name']