django social auth facebook登录

django social auth facebook登录,django,django-socialauth,Django,Django Socialauth,我写的以下代码对一些facebook用户来说是正确的,但对一些用户来说不是。。。有谁能告诉我,我的写作顺序是否错误 这是我的设置.py LOGIN_URL = '/dashboard/' LOGIN_REDIRECT_URL = '/' LOGIN_ERROR_URL = '/dashboard/' SOCIAL_AUTH_UID_LENGTH = 16 FACEBOOK_EXTENDED_PERMISSIONS = [ 'public_profile', 'email'

我写的以下代码对一些facebook用户来说是正确的,但对一些用户来说不是。。。有谁能告诉我,我的写作顺序是否错误

这是我的设置.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 
My URL.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()

试试python social auth,看看本教程。我不喜欢公布全部代码


享受…

虽然这可以从理论上回答问题,但在此处包含答案的基本部分,并提供链接供参考。