本文介绍了在python-social-auth中从Google和Facebook检索个人资料图片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何通过扩展管道使用python-social-auth从Google和Facebook检索个人资料图片和出生日期?我已经读到可以创建函数并设置它们的路径,但我不知道必须检索的属性名称。
How can I retrieve profile picture and date of birth from google and facebook using python-social-auth by extending pipeline? I've read that I can make functions to do so and set path to them but I don't know the attribute names that I must retrieve. Please help!
推荐答案
要通过社交登录获取头像,您需要在应用中创建pipeline.py文件并添加以下行到settings.py:
To get avatars from social login, you need create a pipeline.py file in your app and add this lines to settings.py:
SOCIAL_AUTH_PIPELINE = (
'social.pipeline.social_auth.social_details',
'social.pipeline.social_auth.social_uid',
'social.pipeline.social_auth.auth_allowed',
'social.pipeline.social_auth.social_user',
'social.pipeline.user.get_username',
'social.pipeline.user.create_user',
'social.pipeline.social_auth.associate_user',
'social.pipeline.social_auth.load_extra_data',
'social.pipeline.user.user_details',
'apps.users.pipeline.get_avatar', # This is the path of your pipeline.py
#and get_avatar is the function.
)
,然后将此内容添加到您的pipeline.py文件中
and later add this content to your pipeline.py file
def get_avatar(backend, strategy, details, response,
user=None, *args, **kwargs):
url = None
if backend.name == 'facebook':
url = "http://graph.facebook.com/%s/picture?type=large"%response['id']
if backend.name == 'twitter':
url = response.get('profile_image_url', '').replace('_normal','')
if backend.name == 'google-oauth2':
url = response['image'].get('url')
ext = url.split('.')[-1]
if url:
user.avatar = url
user.save()
这篇关于在python-social-auth中从Google和Facebook检索个人资料图片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!