我写的以下代码对于一些facebook用户来说是正常的,但是对于一些用户来说它不是......任何人都可以告诉我,如果我写错了管道顺序吗?
这是我的Settings.py
LOGIN_URL = '/dashboard/'
LOGIN_REDIRECT_URL = '/'
LOGIN_ERROR_URL = '/dashboard/'
SOCIAL_AUTH_UID_LENGTH = 16
FACEBOOK_EXTENDED_PERMISSIONS = [ 'public_profile', 'email', 'user_location', 'user_hometown', 'user_birthday']
SOCIAL_AUTH_FACEBOOK_EXTRA_DATA = [ ('location', 'location'),('gender','gender'),('hometown', 'hometown')]
SOCIAL_AUTH_USERNAME_IS_FULL_EMAIL = True
SOCIAL_AUTH_CLEAN_USERNAMES = False
SOCIAL_AUTH_PIPELINE = (
'social_auth.backends.pipeline.social.social_auth_user',
'social_auth.backends.pipeline.associate.associate_by_email',
'social_auth.backends.pipeline.user.get_username',
'social_auth.backends.pipeline.user.create_user',
'social_auth.backends.pipeline.social.associate_user',
'social_auth.backends.pipeline.social.load_extra_data',
'social_auth.backends.pipeline.user.update_user_details',
'social_auth_login.pipeline.save_create_user',
)
TEMPLATE_CONTEXT_PROCESSORS = (
'django.contrib.auth.context_processors.auth',
'django.core.context_processors.i18n',
'django.core.context_processors.request',
'django.core.context_processors.media',
'django.core.context_processors.static',
'cms.context_processors.media',
'sekizai.context_processors.sekizai',
'django.core.context_processors.debug',
'social_auth.context_processors.social_auth_by_type_backends',
'social_auth.context_processors.social_auth_by_name_backends',
'social_auth.context_processors.social_auth_backends',
'social_auth.context_processors.social_auth_login_redirect',
)
以下函数用于存储额外数据:
def save_create_user(backend, user, response, *args, **kwargs):
'''
Store extra facebook data into customer model
'''
logger.debug(response)
logger.debug(user)
if backend.name == 'facebook':
profile = user.get_profile()
if profile is None:
profile = Customer(user=user.username)
url = 'https://graph.facebook.com/{0}/picture?redirect=false&access_token={1}' #Picture
我的urls.py:
profile_pic_url = dsa_urlopen(url.format( response.get('id'),response.get('access_token')))
data = simplejson.load(profile_pic_url)
profile.email = response.get('email') # User email
if data['data'] != '':
if data['data']['is_silhouette'] == False:
profile.image_url = data['data']['url'] # image url
else:
profile.image_url = ''
profile.facebook_id = response.get('id') # facebook id
#profile.age = age_range
gender = response.get('gender')
if gender != '':
if gender =='male':
user_gen ='Male'
else:
user_gen ='Female'
profile.gender =user_gen # gender
profile.save()
答案 0 :(得分:0)
尝试使用python-social-auth并查看本教程。我不喜欢发布整个代码.. http://www.artandlogic.com/blog/2014/04/tutorial-adding-facebooktwittergoogle-authentication-to-a-django-application/
...享受