python-social-auth icon indicating copy to clipboard operation
python-social-auth copied to clipboard

Facebook Graph API v2.4

Open mashihill opened this issue 11 years ago • 25 comments

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

mashihill avatar Jul 10 '15 11:07 mashihill

+1

aisayko avatar Jul 22 '15 13:07 aisayko

+1

alex-lokk avatar Jul 24 '15 14:07 alex-lokk

+1

scottlow avatar Jul 25 '15 22:07 scottlow

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'] 

alex-lokk avatar Jul 26 '15 09:07 alex-lokk

Thanks for your solution.

How I can recover the email users who are already registered before the solution?

christianmls avatar Jul 27 '15 19:07 christianmls

Thanks highcat. Your solution seems to be working.

aaj avatar Aug 14 '15 01:08 aaj

Thanks!

macolo avatar Aug 15 '15 22:08 macolo

Thanks!

po5i avatar Aug 19 '15 18:08 po5i

:+1: Put in docs please.

SalahAdDin avatar Aug 20 '15 13:08 SalahAdDin

Thanks! Please, update the docs.

romanovskiy-k avatar Aug 27 '15 16:08 romanovskiy-k

and twitter? email = "" ?

kellycreativo avatar Oct 30 '15 19:10 kellycreativo

I tried setting SOCIAL_AUTH_FACEBOOK_PROFILE_EXTRA_PARAMS, didn't work for me.
Has the API been changed again?

diegoponciano avatar Nov 01 '15 22:11 diegoponciano

If I work with facebook to twitter the issue is not cast me email

kellycreativo avatar Nov 02 '15 01:11 kellycreativo

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 ?

Amar-Chaudhari avatar Nov 13 '15 09:11 Amar-Chaudhari

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?

evcb avatar Dec 14 '15 23:12 evcb

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.

alex-lokk avatar Dec 15 '15 09:12 alex-lokk

@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.

evcb avatar Dec 16 '15 23:12 evcb

@christianmls the next time user logs in with facebook their email will be added to profile.

zixan avatar May 29 '16 07:05 zixan

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'
        #...
)

PabloLefort avatar Sep 28 '16 12:09 PabloLefort

It works for for facebook but not for LinkedIn. What is the solution for LinkedIn?

harunurkst avatar Oct 16 '16 05:10 harunurkst