-2

I've tried this code to find name of friends on facebook in python but it's not working

import facebook

token='my token'

graph= facebook.GraphAPI(token)

profile=graph.get_object("me")  #extracting your own profile

friends=graph.get_connections("me","friends")['data']

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

print friend_list

The error: SyntaxError: Missing parentheses in call to 'print'

luschn
  • 68,448
  • 8
  • 104
  • 118
hussain
  • 654
  • 1
  • 6
  • 23

2 Answers2

6

try this :)

token = 'mytoken'

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

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

print friend_list
tabassum
  • 1,060
  • 6
  • 17
4

That error means you are using Python 3 with code from Python 2, try this:

print(friend_list)

Source: What does "SyntaxError: Missing parentheses in call to 'print'" mean in Python?

Btw, i have no clue about Python (i just inserted the error message into Google), but if friend_list is an array, you may want to try this instead:

print(', '.join(friend_list))

Also, just in case you don´t kow, you can only get access to friends who authorized your App with user_friends too. See this thread for more information: Facebook Graph Api v2.0+ - /me/friends returns empty, or only friends who also use my app

Community
  • 1
  • 1
luschn
  • 68,448
  • 8
  • 104
  • 118