How can I get facebook user id with django-allauth?

I want to display the current_user image in my template. How can I access facebook user id when i use django-allauth?

+11
python django django-allauth
Aug 31 '12 at 20:23
source share
1 answer

For each user registered through a social account, an instance of SocialAccount is available. This model has a foreign key for User . Please note that a user can connect several social network accounts to his local account, so in practice several instances of SocialAccount may be available.

How you want to deal with this depends on the project. I can imagine that you want to copy the profile picture locally or perhaps want to give preference to the Google+ profile picture above Facebook, etc.

The SocialAccount model has some helper methods that give you access to the basics of an account, such as a profile picture. All in all, this is a quick and dirty way to access the first available profile picture:

 {{user.socialaccount_set.all.0.get_avatar_url}} 

Identifier is also available:

 {{user.socialaccount_set.all.0.uid}} 

See also: https://github.com/pennersr/django-allauth/blob/master/allauth/socialaccount/models.py#L72

+25
Sep 01
source share



All Articles