2015-05-22 40 views
0

我的Django項目允許用戶使用python-social-auth的django集成以Google或Facebook個人資料登錄。從python-social-auth獲取django用戶個人資料

他們登錄後,有沒有辦法在Google或Facebook上獲取他們的個人資料鏈接?我試圖做這樣的事情:

from django.db.models.signals import post_save 
from django.dispatch import receiver 
from django.contrib.auth.models import User 
from django.core.mail import mail_admins 

@receiver(post_save, sender=User) 
def alert_new_user(sender, **kwargs): 
    instance = kwargs['instance'] 
    social = instance.social_auth.last() # Assuming .last() gives me the one just added 
    if social is not None: 
     mail_admins('New user resistration', 
      'A new user registered with name {}'.format(instance.get_full_name()), 
      '<html><head/><body>A new user, <a href="{}">{}</a>, registered.</body></html>'.format(
       ???What goes here???, instance.get_full_name() 
      ) 
     ) 

回答

0

你可以得到一個鏈接到他們的Facebook的個人資料,他們在登錄之前

pipeline,有一個叫social_details其獲取信息的功能來自指定社交網絡的用戶。

如果我們看一看這個方法,這是很簡單的:

def social_details(backend, details, response, *args, **kwargs): 
    return {'details': dict(backend.get_user_details(response), 
          **details)} 

,如果你printresponse

def social_details(backend, details, response, *args, **kwargs): 
    print(response) 
    return {'details': dict(backend.get_user_details(response), 
          **details)} 

,你會看到有一個參數link,提供登錄是通過Facbook。現在你可以得到那link並保存/使用它,但是你想要的。

相關問題