1

I'm trying to first get the list of friends from a user who is logged in using a facebook account. I have followed this post with no luck: How to retrieve Facebook friend's information with Python-Social-auth and Django

I get and empty friends set everytime I call the view that is supposed to retrieve the facebook friends. Ideally, I would like to retrieve the facebook friends and have an invite button on the side that invites the user's friends to sign up for web app.

This is what I have in my views.py:

social_user = request.user.social_auth.filter(provider='facebook',).first()
if social_user:
    url = u'https://graph.facebook.com/{0}/' \
          u'friends?fields=id,name,location,picture' \
          u'&access_token={1}'.format(
              social_user.uid,
              social_user.extra_data['access_token'],
          )
request2 = urllib2.Request(url)
friends = json.loads(urllib2.urlopen(request2).read()).get('data')
return render_to_response('friends/friends.html', {'user': request.user, 'friends':friends})
Community
  • 1
  • 1
Michael Smith
  • 3,307
  • 5
  • 25
  • 43

1 Answers1

3

Ever since Graph API 2.0+ You can only get the friends who are using your application. The link you posted shows how it was done in v1.0 which is no longer available.

https://developers.facebook.com/docs/graph-api/reference/v2.2/user/friends

  • A user access token with user_friends permission is required to view the current person's friends.
  • This will only return any friends who have used (via Facebook Login) the app making the request.
  • If a friend of the person declines the user_friends permission, that friend will not show up in the friend list for this person.

So if no friends have used your application and not granted user_friends the list will be empty.

Also for invitable friends https://developers.facebook.com/docs/graph-api/reference/v2.2/user/invitable_friends

The Invitable Friends API is only available to apps classified as Games, which also have a Canvas presence. This API is not available in v1.0. It may be called by mobile games as long as they also have a Canvas presence.

The only way left to do this is https://developers.facebook.com/docs/sharing/reference/send-dialog

phwd
  • 19,975
  • 5
  • 50
  • 78
  • It is also answered in Facebooks own FAQ: https://developers.facebook.com/docs/apps/faq#invite_to_app – WizKid Jan 28 '15 at 00:12
  • 1
    If this is the case, why can sites like pinterest still have this functionality? https://www.pinterest.com/. If you login and click on the top left where it says "invite friends", you will see a facebook invite option. – Michael Smith Feb 13 '15 at 23:03