0

I was playing around with the facebook API and I found this underneath post that I wanted to repeat. It works almost perfectly, except for the fact the print returns an empty array. The friends variable does contain 440 friends. I read that people can block this API with their privacy settings, it seems unlikely all 440 did. Am I doing something wrong? The post is from 2012, updated in 2015, maybe its depricated? Python - Facebook API - Need a working example

Also cant get it working by watching the documentation http://facebook-sdk.readthedocs.io/en/latest/api.html#get-connections

import facebook

token = 'token'
graph = facebook.GraphAPI(token)
friends = graph.get_connections("me", "friends")

friend_list = [friend['name'] for friend in friends['data']]

print (friend_list)
Community
  • 1
  • 1
Zuenie
  • 963
  • 2
  • 11
  • 30
  • 1
    Facebook API is something that was a nightmare to work with. Something is always wrong, something is always missing. I would suggest you to make a raw calls to the Facebook API via Postman or similar tool and check what does it return. – Denis Olehov Feb 07 '17 at 21:25
  • The problem is that you didn't read the documentation for me/friends. It only returns friends that granted user_friends permission to th eapp – WizKid Feb 07 '17 at 21:52
  • Well I generated the token when I declared I give the user_friends permission. And then I stream my own account. Printing Friends returns it found 440 friends. Then I continue and my print statement of friend_list returns an empty array. So as I state in the question maybe all my 440 friends have the permission blocked. I just think that is unlikely. – Zuenie Feb 07 '17 at 21:56
  • That's not what @WizKid is saying. He's saying that in order for you to get their information they have to __opt in__ to _your_ app – wpercy Feb 07 '17 at 22:04
  • Ah ok then I misunderstood. Let me try if I understand now: So the API only allows to get the name (or any kind of data) of any facebook friend only if they set their permission open to that exact app? Then whats the use of the API. – Zuenie Feb 07 '17 at 22:07
  • It just seems that it should be open. I mean I can see who my friends are on facebook if I just go to the page right? I don't see the privacy issue. – Zuenie Feb 07 '17 at 22:52
  • 1
    When you visit your friend’s info on Facebook, that is between you and your friend. When you are using an app however, there is a third party involved - the app developer. And that app developer could be untrustworthy a.f. for all we know. And therefor, to protect your friend’s privacy, they have to decide whether they want to share their information with that app or not. – CBroe Feb 08 '17 at 09:15

0 Answers0