This is how it worked with me. (from https://github.com/omab/python-social-auth/issues/80)
Add the following code to pipeline.py:
from requests import request, HTTPError
from django.core.files.base import ContentFile
def save_profile_picture(strategy, user, response, details,
is_new=False,*args,**kwargs):
if is_new and strategy.backend.name == 'facebook':
url = 'http://graph.facebook.com/{0}/picture'.format(response['id'])
try:
response = request('GET', url, params={'type': 'large'})
response.raise_for_status()
except HTTPError:
pass
else:
profile = user.get_profile()
profile.profile_photo.save('{0}_social.jpg'.format(user.username),
ContentFile(response.content))
profile.save()
and add to pipelines in settings.py:
SOCIAL_AUTH_PIPELINE += (
'<application>.pipelines.save_profile_picture',
)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…