【发布时间】:2015-11-08 13:14:36
【问题描述】:
这是我在settings.py 中的管道:
SOCIAL_AUTH_PIPELINE = (
'social.pipeline.social_auth.social_details',
'social.pipeline.social_auth.social_uid',
'social.pipeline.social_auth.auth_allowed',
'social.pipeline.social_auth.social_user',
'social.pipeline.user.get_username',
'accounts.pipeline.create_user',
'accounts.pipeline.update_user_social_data',
# 'social.pipeline.user.create_user',
'social.pipeline.social_auth.associate_user',
'social.pipeline.social_auth.load_extra_data',
'social.pipeline.user.user_details',
)
连同这一行:
SOCIAL_AUTH_FACEBOOK_SCOPE = ['email']
我也试过了:
FACEBOOK_EXTENDED_PERMISSIONS = ['email']
在我的pipeline.py:
def create_user(strategy, details, user=None, *args, **kwargs):
if user:
return {
'is_new': False
}
fields = dict((name, kwargs.get(name) or details.get(name))
for name in strategy.setting('USER_FIELDS',
USER_FIELDS))
if not fields:
return
if strategy.session_get('signup') == 'UserType1':
user1 = UserType1.objects.create_user(username=fields.get('username'))
user1.user_type = User.USERTYPE1
user1.save()
return {
'is_new': True,
'user': user1
}
elif strategy.session_get('signup') == 'UserType2':
user2 = UserType2.objects.create_user(username=fields.get('username'))
user2.user_type = User.USERTYPE2
user2.save()
return {
'is_new': True,
'user': user2
}
def update_user_social_data(strategy, *args, **kwargs):
if not kwargs['is_new']:
return
full_name = ''
backend = kwargs['backend']
user = kwargs['user']
full_name = kwargs['response'].get('name')
user.full_name = full_name
email = kwargs['response'].get('email')
user.email = email
user.save()
但是,kwargs['response'].get('name') 正确返回用户的全名,但 kwargs['response'].get('email') 始终为无。当我做print kwargs['response'] 时,它只显示uid 和用户名,所以Facebook 不会返回用户的电子邮件。如何克服这一点?谢谢!
【问题讨论】:
标签: python django facebook django-socialauth python-social-auth