Retrieving profile picture from google and facebook in python-social-auth

后端 未结 3 768
既然无缘
既然无缘 2021-02-03 12:31

How can I retrieve profile picture and date of birth from google and facebook using python-social-auth by extending pipeline? I\'ve read that I can make functions to do so and s

3条回答
  •  名媛妹妹
    2021-02-03 12:54

    The above answers may not work (it did not work for me) as the facebook profile URL does not work anymore without accesstoken. The following answer worked for me.

    def save_profile(backend, user, response, is_new=False, *args, **kwargs):
        if is_new and backend.name == "facebook":
            # The main part is how to get the profile picture URL and then do what you need to do
            Profile.objects.filter(owner=user).update(
                imageUrl='https://graph.facebook.com/{0}/picture/?type=large&access_token={1}'.format(response['id'],
                                                                                                      response[
                                                                                                          'access_token']))
        elif backend.name == 'google-oauth2':
            if is_new and response.get('picture'):
                Profile.objects.filter(owner=user).update(imageUrl=response['picture'])
    

    add to the pipeline in setting.py,

    SOCIAL_AUTH_PIPELINE+ = ('.save_profile')
    

提交回复
热议问题