我想做什么?
我正在尝试从社会账户中获取数据。为此,我正在跟踪这站点。
有什么问题?
在成功登录到我的facebook帐户后,我收到了以下错误:
错误:IndexError at /accounts/facebook/login/callback/
list index out of range
我在网上查了一下,看到了这的帖子,并试图实现它,但这给了我一个keyerror 'user'。
我的代码:
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' 发布于 2018-01-10 14:56:13
终于找到了解决方案:
我没有使用SocialAccount模型获取用户数据,而是使用传递的参数sociallogin获取用户数据,如下所示:
解决方案:
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 改变了这一点:
account_uid = SocialAccount.objects.filter(user_id=request.user.id, provider='facebook')to此文:
if sociallogin.account.provider == 'facebook':
first_name = sociallogin.account.extra_data['first_name']https://stackoverflow.com/questions/48166506
复制相似问题