[Django]-Django invite friends from social account

0👍

To expand on @adamkg’s comment:

After signing up users via social_auth, you may get the stored data from their social provider’s (usually basic things like avatar, id and username) by calling the get_social_auth_for_user method of the UserSocialAuth class.

Some providers stores different extra data, according to this setting, and you may extend this data using a custom pipeline step. For an example of this, have a look at this related question.

Additionally, all providers store tokens and uid, so you can request data as the user’s at any time.

So, to get facebook user friends in your view you might do:

social_data = UserSocialAuth.get_social_auth_for_user(request.user)
if social_data.provider == 'facebook':  # get facebook friends
    auth_tokens = social_data.tokens['access_token']
    graph = facebook.GraphAPI(auth_tokens)
    friends = graph.get_connections("me", "friends")
    # now do something with friends ...

In the example above I used facebook which was the first facebook graph client I found on the net: facebook-sdk, which is also available on pypi

Leave a comment