我试图通过django-social-auth从Facebook获取用户个人资料照片。
我在另一篇文章中看到,我应该从Facebook获取用户uid才能访问个人资料图片。 我怎样才能获得这个uid?
来自django-social-auth我刚刚安装了它,并使用django-registrations配置了登录/注销的基本内容。
这是我登录的html: 用FB登录
我如何向家庭提出要求?在Facebook中查看用户并获取uid?
我在django-socail-auth docs中找到了这个:
def social_associate_and_load_data(backend, details, response, uid, user,
social_user=None, *args, **kwargs):
"""
The combination of associate_user and load_extra_data functions
of django-social-auth. The reason for combining these two pipeline
functions is decreasing the number of database visits.
"""
extra_data = backend.extra_data(user, uid, response, details)
created = False
if not social_user and user:
social_user, created = UserSocialAuth.objects.get_or_create(
user_id=user.id,
provider=backend.name,
uid=uid,
defaults={'extra_data': extra_data})
if not created and extra_data and social_user.extra_data != extra_data:
social_user.extra_data.update(extra_data)
social_user.save()
return {'social_user': social_user}
我应该把它放在我的django应用程序中?在views.py?如果是,如果我只使用commom social-auth url登录,我该如何激活视图。
答案 0 :(得分:4)
Facebook uid
存储在UserSocialAuth
个实例中,你可以通过
user.social_auth.get(provider='facebook').uid