Bruno Paulino Bruno Paulino - 1 year ago 59
Python Question

How to retrieve Facebook friend's information with Python-Social-auth and Django

How can I retrieve Facebook friend's information using Python-Social-auth and Django? I already retrieve a profile information and authenticate the user, but I want to get more information about their friends and invite them to my app.


You can do it using Facebook API. Firstly, you need obtain the token of your Facebook application (FACEBOOK_APP_ACCESS_TOKEN) or from social_user.extra_data['access_token']

Then with this token you can send the requests you need, for example, this code gets all the friends of the authenticated user with their id, name, location, picture:

social_user = request.user.social_auth.filter(
if social_user:
    url = u'{0}/' \
          u'friends?fields=id,name,location,picture' \
    request = urllib2.Request(url)
    friends = json.loads(urllib2.urlopen(request).read()).get('data')
    for friend in friends:
        # do something

Depending on what fields you want to get you can set the permissions here: -> Your App -> App Details -> App Centre Permissions

or set your permissions in