Reputation: 446
first of all I would like to apologize to the community if this is a repost. I was searching stackoverflow for something that might help me on this matter but my search ended with no success. So here comes my problem.
Maybe it's my lack of skills, but I personally couldn't quite figure my way out through django_facebook documentation. I went through the whole thing and even though I think that all of the pieces are explained well, creating the big picture was pretty hard for me...
I managed to connect django_facebook with an app on facebook and even login, but what I couldn't do is pull information about the user who is logged in. My goal is to allow users to login/register with Facebook on my website, and pull their basic information from Facebook so that I can suggest them as User information for their profile on my website.
I would be really thankful, if you can explain the whole login/register and getting informations about the user process thoroughly.
p.s. someone suggested django_allauth to me. Should I switch to that? If yes, what would be the pros&cons of both djang_facebook and django_allauth? p.p.s. Also I wasn't able to find any decent tutorial for django_facebook nor django_allauth. If you have any, please gimme the links :)
Upvotes: 2
Views: 535
Reputation: 776
Here is a tutorial explaining how to use all_auth for social authentication.
You can access the data from the allauth object directly, using a code snippet like the following in your view
:
First, get information from the account using:
account_uid = SocialAccount.objects.filter(user_id=request.user.id, provider='facebook')
Then, using member attributes like given below, you can get the parameters which have been made public.
account_uid[0].get_avatar_url()
account_uid[0].extra_data['username']
account_uid[0].extra_data['first_name']
account_uid[0].extra_data['last_name']
account_uid[0].extra_data['gender']
account_uid[0].extra_data['email']
account_uid[0].extra_data['link']
account_uid[0].extra_data['uid']
Upvotes: 1
Reputation: 818
A quick overview of django-facebook suggest me that the information are saved in
BaseFacebookModel
So there is signal called post_connect. You can use that fetch the information from above model and save it to your profile if you want.
Also in django-allauth it can be easily done. I have done it for fetching the date of birth. There is a model called SocialAccount which store the public information of user. The extra data is store in the form of json. You can simply use that data and use it in UserProfile after allauth authenticate the user.
Let me know if it helps.
Upvotes: 1