2014-11-22 106 views
2

我寫的下面的代碼是爲一些Facebook用戶正確工作,但對於一些用戶它不...可以告訴我,如果我寫錯誤的管道順序?django社交auth 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() 

回答