Fil*_*ano 1 django django-socialauth
我正在尝试使用 django-social-auth 从 Facebook 获取用户个人资料图片。
我在另一篇文章中看到,我应该从 Facebook 获取用户 uid 才能访问个人资料图片。我怎样才能得到uid?
从 django-social-auth 我刚刚安装了它并配置了基本的东西以使用 django-registrations 登录/注销。
这是我要登录的 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}
Run Code Online (Sandbox Code Playgroud)
我应该把它放在我的 django 应用程序中的什么位置?在views.py中?如果是,如果我只是使用公共社交身份验证网址登录,我该如何激活该视图。
Facebookuid存储在UserSocialAuth实例中,您可以通过这样做来获取
user.social_auth.get(provider='facebook').uid
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2178 次 |
| 最近记录: |