Saturday, June 29, 2013

How to get facebook oauth_access_token

1- create facebook app

https://www.facebook.com/developers/

2- use the App ID:  and Site URL: to generate the   oauth_access_token


3-  use the following url to generate oauth_access_token


 https://graph.facebook.com/oauth/authorize?type=user_agent&client_id=xxxxxxxxxxxxxxxx&redirect_uri=http%3A%2F%2Fgentle-temple-6178.herokuapp.com/&scope=read_stream,offline_access

client_id = App ID
redirect_uri = Site URL


4- the return URL will contain the  oauth_access_token


http://gentle-temple-6178.herokuapp.com/#access_token=932750932000980340aa0afaf789a9f9af79a7f97d99a79799a7&expires_in=5496



5- Sample code to get friend list using python

#!/usr/bin/python

import facebook

token = '932750932000980340aa0afaf789a9f9af79a7f97d99a79799a7'

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

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

print friend_list




Note:

you have to install https://github.com/pythonforfacebook/facebook-sdk to make the code work

No comments:

Post a Comment