gpt4 book ai didi

python - 在 python-social-auth 中从 google 和 facebook 检索个人资料图片

转载 作者:太空狗 更新时间:2023-10-29 20:39:33 25 4
gpt4 key购买 nike

如何通过扩展管道使用 python-social-auth 从 google 和 facebook 检索个人资料图片和出生日期?我读过我可以创建函数来执行此操作并为它们设置路径,但我不知道我必须检索的属性名称。请帮忙!

最佳答案

要从社交登录获取头像,您需要在您的应用中创建一个 pipeline.py 文件并将以下行添加到 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 文件

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 - 在 python-social-auth 中从 google 和 facebook 检索个人资料图片,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29575713/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com