用Django社交认证从Facebook获取用户uid
我试图从django-social-auth获取来自Facebook的用户个人资料图片。用Django社交认证从Facebook获取用户uid
我在另一篇文章中看到,我应该从Facebook获得用户uid才能访问个人资料图片。 我如何获得uid?
从django-social-auth我刚刚安装了它,并配置了基本的东西登录/登出与Django的注册。
这是我的HTML登录: 登录与FB
如何我可以做一个“家”的视图的请求用户在Facebook和获得UID?
我发现这个在Django的socail-auth的文档:
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中?如果是的话,我如何才能激活视图,如果我只是通过社交认证网站登录。
回答:
的Facebook uid
存储在UserSocialAuth
例如,你可以通过做得到它
user.social_auth.get(provider='facebook').uid
以上是 用Django社交认证从Facebook获取用户uid 的全部内容, 来源链接: utcz.com/qa/261166.html