python-social-auth Facebook and LinkedIn user's email is empty

有些话、适合烂在心里 提交于 2019-12-11 14:06:24

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!