Django Social Auth: Receive an Email from linkedin, twitter & facebook

I am using the Django social_auth api to login through a social account. Here I want to get the email address from a social account and save it in my database table. Name and surname can be obtained from the account, but I can not get the email address, profile picture. Share your ideas on extracting these details from your social account.

+4
source share
1 answer

Twitter does not open emails in order to receive the Facebook email that you need to determine FACEBOOK_EXTENDED_PERMISSIONS = ['email'] , LinkedIn email will be automatically downloaded. Emails are stored in the user model under the email attribute.

The profile image can be saved by setting the following parameters:

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

The Facebook profile picture is available to the API and is not sent during the authorization process. You can define your pipeline to store it as follows:

 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() 

Add it to the bottom of the pipeline settings (check the documentation for the pipeline http://django-social-auth.readthedocs.org/en/latest/pipeline.html ). This code has not been tested, so play around with it a bit.

Then you can access the profile picture:

 social = user.social_auth.get(provider='facebook') # or twitter or linkedin social.extra_data['profile_picture'] 
+5
source

Source: https://habr.com/ru/post/1499745/


All Articles