0

What I am trying to do?

I am trying to access the data from the social account. And for that I am following this site.

What is the problem?

I am getting the following error after successfully logged in to my facebook account:

Error: IndexError at /accounts/facebook/login/callback/

list index out of range

Looking it up on the internet I saw this post and tried to implement it but that gave a keyerror 'user'.

My Code:

adaptar.py:

from allauth.socialaccount.adapter import DefaultSocialAccountAdapter
from allauth.socialaccount.models import SocialAccount

class CustomAdapter(DefaultSocialAccountAdapter):

   def pre_social_login(self, request, sociallogin):
      account_uid = SocialAccount.objects.filter(user_id=request.user.id, provider='facebook')
      print account_uid[0].extra_data['first_name']

settings.py:

SOCIALACCOUNT_ADAPTER = 'Authentication.adapter.CustomAdapter' 
Ahtisham
  • 9,170
  • 4
  • 43
  • 57

1 Answers1

0

Finally found the solution:

Instead of using SocialAccount model to get the user data I used the passed parameter sociallogin to get the user data like following:

solution:

adaptar.py:

from allauth.socialaccount.adapter import DefaultSocialAccountAdapter

class CustomAdapter(DefaultSocialAccountAdapter):   
      def pre_social_login(self, request, sociallogin):
         if sociallogin.account.provider == 'facebook':
            first_name = sociallogin.account.extra_data['first_name'] 
            print first_name 

changed this:

 account_uid = SocialAccount.objects.filter(user_id=request.user.id, provider='facebook')

to this:

if sociallogin.account.provider == 'facebook':
   first_name = sociallogin.account.extra_data['first_name']
Ahtisham
  • 9,170
  • 4
  • 43
  • 57