introduction to facebook python api
DESCRIPTION
Facebook Python SDK - IntroductionNational Chengchi UniversitySocial Network and Applications - TA SessionLittleQTRANSCRIPT
![Page 1: Introduction to Facebook Python API](https://reader035.vdocuments.us/reader035/viewer/2022081717/554ef7feb4c90577698b48b2/html5/thumbnails/1.jpg)
f Introduction toFacebook PY API
Introduction to Facebook Python APISocial Network and Applications, 2011LittleQ, The Department of Computer Science, NCCU
![Page 2: Introduction to Facebook Python API](https://reader035.vdocuments.us/reader035/viewer/2022081717/554ef7feb4c90577698b48b2/html5/thumbnails/2.jpg)
f Introduction toFacebook PY API
Objectives
• Learn the concepts of Facebook API
• Learn how to play with Facebook Graph API
![Page 3: Introduction to Facebook Python API](https://reader035.vdocuments.us/reader035/viewer/2022081717/554ef7feb4c90577698b48b2/html5/thumbnails/3.jpg)
f Introduction toFacebook PY API
Core Topics
• Facebook Developers website
• Graph API
• Facebook Python SDK
• Resources
![Page 4: Introduction to Facebook Python API](https://reader035.vdocuments.us/reader035/viewer/2022081717/554ef7feb4c90577698b48b2/html5/thumbnails/4.jpg)
f Introduction toFacebook PY API
Facebook Developers
• Provide you online documentations
• Forum for discussion
• Management of your applications
![Page 5: Introduction to Facebook Python API](https://reader035.vdocuments.us/reader035/viewer/2022081717/554ef7feb4c90577698b48b2/html5/thumbnails/5.jpg)
f Introduction toFacebook PY API
Where is it?
![Page 6: Introduction to Facebook Python API](https://reader035.vdocuments.us/reader035/viewer/2022081717/554ef7feb4c90577698b48b2/html5/thumbnails/6.jpg)
f Introduction toFacebook PY API
Social Plugins
• Like Button, Send Button, Login Button
• Comments
• Your Friends
• Activity Feed, Live Stream
![Page 7: Introduction to Facebook Python API](https://reader035.vdocuments.us/reader035/viewer/2022081717/554ef7feb4c90577698b48b2/html5/thumbnails/7.jpg)
f Introduction toFacebook PY API
Is That What You Want?
![Page 8: Introduction to Facebook Python API](https://reader035.vdocuments.us/reader035/viewer/2022081717/554ef7feb4c90577698b48b2/html5/thumbnails/8.jpg)
f Introduction toFacebook PY API
Graph API
• Facebook’s core
• Social graph
• Connections
Application Graph API Facebook Database
Access Token Request Data
Aggregate InformationResponse Data
![Page 9: Introduction to Facebook Python API](https://reader035.vdocuments.us/reader035/viewer/2022081717/554ef7feb4c90577698b48b2/html5/thumbnails/9.jpg)
f Introduction toFacebook 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
![Page 10: Introduction to Facebook Python API](https://reader035.vdocuments.us/reader035/viewer/2022081717/554ef7feb4c90577698b48b2/html5/thumbnails/10.jpg)
f Introduction toFacebook PY API
Object Model
information from graph API without access token
![Page 11: Introduction to Facebook Python API](https://reader035.vdocuments.us/reader035/viewer/2022081717/554ef7feb4c90577698b48b2/html5/thumbnails/11.jpg)
f Introduction toFacebook PY API
Graph Model
information from graph API with access token
![Page 12: Introduction to Facebook Python API](https://reader035.vdocuments.us/reader035/viewer/2022081717/554ef7feb4c90577698b48b2/html5/thumbnails/12.jpg)
f Introduction toFacebook 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
![Page 13: Introduction to Facebook Python API](https://reader035.vdocuments.us/reader035/viewer/2022081717/554ef7feb4c90577698b48b2/html5/thumbnails/13.jpg)
f Introduction toFacebook PY API
Connection Model
![Page 14: Introduction to Facebook Python API](https://reader035.vdocuments.us/reader035/viewer/2022081717/554ef7feb4c90577698b48b2/html5/thumbnails/14.jpg)
f Introduction toFacebook PY API
Access to Graph
• HTTP(S) Graph API
• SDKs
‣ Javascript SDK
‣ iOS SDK
‣ Android SDK
‣ PHP SDK
‣ Python SDK
![Page 15: Introduction to Facebook Python API](https://reader035.vdocuments.us/reader035/viewer/2022081717/554ef7feb4c90577698b48b2/html5/thumbnails/15.jpg)
f Introduction toFacebook PY API
HTTP(S) Graph API
• RESTful HTTP request & response
• Response data-type: JSON
• Access URL: graph.facebook.com
![Page 16: Introduction to Facebook Python API](https://reader035.vdocuments.us/reader035/viewer/2022081717/554ef7feb4c90577698b48b2/html5/thumbnails/16.jpg)
f Introduction toFacebook PY API
HTTP(S) Graph API
• Request information of an object with id or username
• id-or-username can be “me” with the access token
http://graph.facebook.com/<id-‐or-‐username>
![Page 17: Introduction to Facebook Python API](https://reader035.vdocuments.us/reader035/viewer/2022081717/554ef7feb4c90577698b48b2/html5/thumbnails/17.jpg)
f Introduction toFacebook PY API
HTTP(S) Graph API
{ "id": "1681390745", "name": "Colin Su", "first_name": "Colin", "last_name": "Su", "link": "https://www.facebook.com/littleq0903", "username": "littleq0903", "gender": "male", "locale": "en_US"}
http://graph.facebook.com/littleq0903
Result:
![Page 18: Introduction to Facebook Python API](https://reader035.vdocuments.us/reader035/viewer/2022081717/554ef7feb4c90577698b48b2/html5/thumbnails/18.jpg)
f Introduction toFacebook 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
![Page 19: Introduction to Facebook Python API](https://reader035.vdocuments.us/reader035/viewer/2022081717/554ef7feb4c90577698b48b2/html5/thumbnails/19.jpg)
f Introduction toFacebook PY API
Get Access Token
• GetMyAccesshttp://getmyaccess.heroku.com
• It requires a permission called “offline_access”, so this token can be valid for a long time
![Page 20: Introduction to Facebook Python API](https://reader035.vdocuments.us/reader035/viewer/2022081717/554ef7feb4c90577698b48b2/html5/thumbnails/20.jpg)
f Introduction toFacebook PY API
HTTP(S) Graph API
• Access token should be transferred as a HTTP GET variable
• More information: developers.facebook.com/docs/reference/api/
http://graph.facebook.com/littleq0903?access_token=...
![Page 21: Introduction to Facebook Python API](https://reader035.vdocuments.us/reader035/viewer/2022081717/554ef7feb4c90577698b48b2/html5/thumbnails/21.jpg)
f Introduction toFacebook PY API
Python SDK
• Let you access all features of the Graph API
• That’s all, let’s play!
![Page 22: Introduction to Facebook Python API](https://reader035.vdocuments.us/reader035/viewer/2022081717/554ef7feb4c90577698b48b2/html5/thumbnails/22.jpg)
f Introduction toFacebook 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)
![Page 23: Introduction to Facebook Python API](https://reader035.vdocuments.us/reader035/viewer/2022081717/554ef7feb4c90577698b48b2/html5/thumbnails/23.jpg)
f Introduction toFacebook PY API
Graph
• Depends your access token
• Everyone will have their own graph, could be unique
![Page 24: Introduction to Facebook Python API](https://reader035.vdocuments.us/reader035/viewer/2022081717/554ef7feb4c90577698b48b2/html5/thumbnails/24.jpg)
f Introduction toFacebook PY API
Graph API Class
• Fetch the graph by implement it
import facebook
graph = facebook.GraphAPI()user = graph.get_object(“littleq0903”)
![Page 25: Introduction to Facebook Python API](https://reader035.vdocuments.us/reader035/viewer/2022081717/554ef7feb4c90577698b48b2/html5/thumbnails/25.jpg)
f Introduction toFacebook PY API
Authentication
• Graph can be implemented with an access token
• And the perspective of the graph will be different
my_profile = graph.get_object(“me”)
graph = GraphAPI(ACCESS_TOKEN)
![Page 26: Introduction to Facebook Python API](https://reader035.vdocuments.us/reader035/viewer/2022081717/554ef7feb4c90577698b48b2/html5/thumbnails/26.jpg)
f Introduction toFacebook PY API
Graph Methods
• get_object, get_objects
• get_connections
• put_object
• put_wall_post, put_comment, put_like
• delete_object
![Page 27: Introduction to Facebook Python API](https://reader035.vdocuments.us/reader035/viewer/2022081717/554ef7feb4c90577698b48b2/html5/thumbnails/27.jpg)
f Introduction toFacebook PY API
Demo
![Page 28: Introduction to Facebook Python API](https://reader035.vdocuments.us/reader035/viewer/2022081717/554ef7feb4c90577698b48b2/html5/thumbnails/28.jpg)
f Introduction toFacebook PY API
Homework
• Fetch a kind of data on the FB Graph
• Do some statistics on it
• Don’t Copy from others
![Page 29: Introduction to Facebook Python API](https://reader035.vdocuments.us/reader035/viewer/2022081717/554ef7feb4c90577698b48b2/html5/thumbnails/29.jpg)
f Introduction toFacebook PY API
Q&A TimeThanks for your listening