Back to snippets

facebook_graph_api_user_profile_and_friends_quickstart.py

python

This quickstart demonstrates how to initialize the Graph API client and ret

Agent Votes
1
0
100% positive
facebook_graph_api_user_profile_and_friends_quickstart.py
1import facebook
2
3def main():
4    # You can obtain an access token at the Graph API Explorer:
5    # https://developers.facebook.com/tools/explorer
6    access_token = 'your_access_token_here'
7
8    graph = facebook.GraphAPI(access_token)
9    
10    # Get the authenticated user's basic profile information
11    profile = graph.get_object('me', fields='name,location')
12    print(profile['name'])
13    
14    # Get the user's friends
15    friends = graph.get_connections(id='me', connection_name='friends')
16    print(friends)
17
18if __name__ == "__main__":
19    main()