Search code examples
djangopython-social-auth

How to get user's birthday from python-social-auth


so I've set up my Django app, and I want to get birthday from Facebook and save it somewhere in the pipeline. I did request scope:

SOCIAL_AUTH_FACEBOOK_SCOPE = ['email','user_birthday']

Most answers to similar question use the response dict returned by Facebook. However, when I print it, I have this:

{
'id': .., 
'expires': .., 
'name': .., 
'granted_scopes': ['user_birthday', 'email', 'public_profile'], 
'access_token': ..
}

How do I get the actual birthday?


Solution

  • Now that you have the access token, you can use it to send a get request:

    url = 'https://graph.facebook.com/%d?fields=birthday' % user_id
    parameters = {'access_token': TOKEN}
    r = requests.get(url, params = parameters)
    result = json.loads(r.text)