pythondjangodjango-allauthdjango-facebook

Getting information about the user from Facebook using django_facebook


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 :)


Solution

  • 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']