Introduction to Facebook Python API
Social Network and Applications, 2011
LittleQ, The Department of Computer Science, NCCU
Introduction to
Facebook PY API
Objectives
Learn the concepts of Facebook API
Learn how to play with Facebook Graph
API
Introduction to
Facebook PY API
Core Topics
Facebook Developers website
Graph API
Facebook Python SDK
Resources
Introduction to
Facebook PY API
Facebook Developers
Provide you online documentations
Forum for discussion
Management of your applications
Introduction to
Facebook PY API
Where is it?
Introduction to
Facebook PY API
Social Plugins
Like Button, Send Button, Login Button
Comments
Your Friends
Activity Feed, Live Stream
Introduction to
Facebook PY API
Is That What You Want?
Introduction to
Facebook PY API
Graph API
Response Data
Aggregate Information
Access Token
Request Data
Application
Graph API
Facebook Database
Facebooks core
Social graph
Connections
Introduction to
Facebook PY API
Graph Model
Composed of objects and connections
Identify entities and relationships by id
Data will be stored with smallest spaces
and keep being updated
Introduction to
Facebook PY API
Object Model
information from graph API
without access token
Introduction to
Facebook PY API
Graph Model
information from graph API
with access token
Introduction to
Facebook PY API
Connection Model
All of the object in the Facebook social graph are connected
to each other via connections
Objects are just like entities while connections are like
relationship
For example, users, pages and groups are objects and likes,
friends and feeds are connections
Introduction to
Facebook PY API
Connection Model
Introduction to
Facebook PY API
Access to Graph
HTTP(S) Graph API
SDKs
Javascript SDK
iOS SDK
Android SDK
PHP SDK
Python SDK
Introduction to
Facebook PY API
HTTP(S) Graph API
RESTful HTTP request & response
Response data-type: JSON
Access URL: graph.facebook.com
Introduction to
Facebook PY API
HTTP(S) Graph API
http://graph.facebook.com/<id-or-username>
Request information of an object with id or username
id-or-username can be me with the access token
Introduction to
Facebook PY API
HTTP(S) Graph API
http://graph.facebook.com/littleq0903
Result:
{
"id":
"1681390745",
"name":
"Colin
Su",
"first_name":
"Colin",
"last_name":
"Su",
"link":
"https://www.facebook.com/littleq0903",
"username":
"littleq0903",
"gender":
"male",
"locale":
"en_US"
}
Introduction to
Facebook PY API
Access Token
A long string stands for the authentication of users
Temporary
The information behind the access token
user id
app id
expired time
secret
Introduction to
Facebook PY API
Get Access Token
GetMyAccess
http://getmyaccess.heroku.com
It requires a permission called
oine_access, so this token can be valid
for a long time
Introduction to
Facebook PY API
HTTP(S) Graph API
Access token should be transferred as a
HTTP GET variable
http://graph.facebook.com/littleq0903?access_token=...
More information:
developers.facebook.com/docs/reference/
api/
Introduction to
Facebook PY API
Python SDK
Let you access all features of the Graph API
Thats all, lets play!
Introduction to
Facebook PY API
Python SDK
https://github.com/facebook/python-sdk
Designed to support Graph API and FB
Javascript SDK (You will learn in the future)
Introduction to
Facebook PY API
Graph
Depends your access token
Everyone will have their own graph, could
be unique
Introduction to
Facebook PY API
Graph API Class
Fetch the graph by implement it
import
facebook
graph
=
facebook.GraphAPI()
user
=
graph.get_object(littleq0903)
Introduction to
Facebook PY API
Authentication
my_profile
=
graph.get_object(me)
Graph can be implemented with an access
token
graph
=
GraphAPI(ACCESS_TOKEN)
And the perspective of the graph will be
dierent
Introduction to
Facebook PY API
Graph Methods
get_object, get_objects
get_connections
put_object
put_wall_post, put_comment, put_like
delete_object
Introduction to
Facebook PY API
Demo
Introduction to
Facebook PY API
Homework
Fetch a kind of data on the FB Graph
Do some statistics on it
Dont Copy from others
Introduction to
Facebook PY API
Q&A Time
Thanks for your listening
Introduction to
Facebook PY API