问题
I am developing a Django web app using python-social-auth. I have this in my Django settings:
SOCIAL_AUTH_GOOGLE_OAUTH2_KEY = 'xxx'
SOCIAL_AUTH_GOOGLE_OAUTH2_SECRET = 'xxx'
SOCIAL_AUTH_FACEBOOK_KEY = 'xxx'
SOCIAL_AUTH_FACEBOOK_SECRET = 'xxx'
SOCIAL_AUTH_FACEBOOK_SCOPE = ['email',]
SOCIAL_AUTH_LINKEDIN_OAUTH2_KEY = 'xxx'
SOCIAL_AUTH_LINKEDIN_OAUTH2_SECRET = 'xxx'
SOCIAL_AUTH_LINKEDIN_OAUTH2_SCOPE = ['r_basicprofile', 'r_emailaddress']
Now Google sets user's email just fine in auth.user model in database, but LinkedIn and Facebook won't even send the user's email. What do I do?
回答1:
Add this to your settings:
SOCIAL_AUTH_FACEBOOK_PROFILE_EXTRA_PARAMS = {'fields': 'id,name,email',}
SOCIAL_AUTH_FIELD_SELECTORS = ['email-address',]
Now Facebook and LinkedIn will send user's email and python-social-auth will automatically set them to User model in the database.
Hope this helps someone.
来源:https://stackoverflow.com/questions/46807906/python-social-auth-facebook-and-linkedin-users-email-is-empty