2013-08-30 38 views

回答

5

Twitter不會透露電子郵件,要檢索您需要定義的電子郵件地址FACEBOOK_EXTENDED_PERMISSIONS = ['email'],LinkedIn電子郵件會自動檢索。電子郵件存儲在email屬性下的用戶模型中。

檔案圖片可以存儲通過定義這樣的設置:

TWITTER_EXTRA_DATA = [('profile_image_url', 'profile_picture')] 
LINKEDIN_EXTRA_DATA = [('picture-url', 'profile_picture')] 

的Facebook簡檔的畫面是由API訪問,並在將已授權過程不被髮送。您可以定義管道,將其存儲這樣的:

from django.utils import simplejson 
from social_auth.utils import dsa_urlopen 

def facebook_profile_picture(backend, user, social_user, details, response, *args, **kwargs): 
    if backend.name != 'facebook': 
     return 
    url = 'https://graph.facebook.com/{0}/picture?redirect=false&access_token={1}' 
    response = dsa_urlopen(url.format(social_user.extra_data['id'], social_user.extra_data['access_token']) 
    data = simplejson.load(response) 
    social_user.extra_data['profile_picture'] = data['data']['url'] 
    social_user.save() 

將它添加到管道設置(檢查管線DOC在http://django-social-auth.readthedocs.org/en/latest/pipeline.html)的底部。這段代碼沒有經過測試,所以請稍等一下。

然後你就可以訪問個人資料圖片做:

social = user.social_auth.get(provider='facebook') # or twitter or linkedin 
social.extra_data['profile_picture'] 
相關問題