python-social-auth Facebook and LinkedIn user'

2019-08-16 23:46发布

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条回答
啃猪蹄的小仙女
2楼-- · 2019-08-17 00:30

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.

查看更多
登录 后发表回答