Facebook Graph API v2.4
Facebook updates it API recently, it seems that the way to get extra scope is not working now. e.g. setting SOCIAL_AUTH_FACEBOOK_SCOPE = ['email'] does not return the email.
here's the link to graph API v2.4 https://developers.facebook.com/blog/post/2015/07/08/graph-api-v2.4/?ref=hp
+1
+1
+1
I found solution: now you need to request email field explicitly to retrieve it from Facebook, so just add this to your settings:
SOCIAL_AUTH_FACEBOOK_PROFILE_EXTRA_PARAMS = {
'fields': 'id,name,email', # needed starting from protocol v2.4
}
UP of course you need to set scope also:
SOCIAL_AUTH_FACEBOOK_SCOPE = ['email']
Thanks for your solution.
How I can recover the email users who are already registered before the solution?
Thanks highcat. Your solution seems to be working.
Thanks!
Thanks!
:+1: Put in docs please.
Thanks! Please, update the docs.
and twitter? email = "" ?
I tried setting SOCIAL_AUTH_FACEBOOK_PROFILE_EXTRA_PARAMS, didn't work for me.
Has the API been changed again?
If I work with facebook to twitter the issue is not cast me email
I updated SOCIAL_AUTH_FACEBOOK_PROFILE_EXTRA_PARAM, but doesnt seem to work. Do we need to update API version in https://github.com/omab/python-social-auth/blob/master/social/backends/facebook.py ?
SOCIAL_AUTH_FACEBOOK_PROFILE_EXTRA_PARAMS works for me on Facebook, but doesn't work for Twitter. Any ideas on how to get the e-mail?
As I remember, there was NO way to get email from twitter, Twitter API won't return it (and everybody was frustrated about that). Check it's API first, maybe things changed.
@highcat. I found this: http://stackoverflow.com/questions/22627083/can-we-get-email-id-from-twitter-oauth-api
It migh be worth trying. I have submitted a request. Let's see what happens.
@christianmls the next time user logs in with facebook their email will be added to profile.
Hi!
A work arround using Django 1.10, Python Social Auth 0.2.21 and Requests 2.11.1 to get email of user with facebook strategy:
@partial
def require_email(strategy, details, user=None, is_new=False, *args, **kwargs):
if user and user.email:
return
elif is_new and not details.get('email'):
if strategy.request_data().get('email'):
details['email'] = strategy.request_data().get('email')
return
if strategy.request.session.get('email', '') != '':
details['email'] = strategy.request.session['email']
return
fbuid = kwargs['response']['id']
token = kwargs['response']['access_token']
url = 'https://graph.facebook.com/{0}/?' \
'fields=email&access_token={1}'.format(fbuid, token)
resp = requests.get(url)
if resp.json().get('email'):
details['email'] = resp.json().get('email')
else:
return redirect('myapp:email-required')
And in settings:
SOCIAL_AUTH_PIPELINE = (
#...
'social.pipeline.social_auth.social_user',
'myapp.pipeline.require_email'
#...
)
It works for for facebook but not for LinkedIn. What is the solution for LinkedIn?