Introduction to Facebook Python API

14,467 views

Published on

Facebook Python SDK - Introduction
National Chengchi University
Social Network and Applications - TA Session
LittleQ

Published in: Technology
2 Comments
17 Likes
Statistics
Notes
No Downloads
Views
Total views
14,467
On SlideShare
0
From Embeds
0
Number of Embeds
32
Actions
Shares
0
Downloads
227
Comments
2
Likes
17
Embeds 0
No embeds

No notes for slide

Introduction to Facebook Python API

  1. 1. Introduction to Facebook Python APISocial Network and Applications, 2011LittleQ, The Department of Computer Science, NCCU f Introduction to Facebook PY API
  2. 2. Objectives• Learn the concepts of Facebook API• Learn how to play with Facebook Graph API f Introduction to Facebook PY API
  3. 3. Core Topics• Facebook Developers website• Graph API• Facebook Python SDK• Resources f Introduction to Facebook PY API
  4. 4. Facebook Developers• Provide you online documentations• Forum for discussion• Management of your applications f Introduction to Facebook PY API
  5. 5. Where is it? f Introduction to Facebook PY API
  6. 6. Social Plugins• Like Button, Send Button, Login Button• Comments• Your Friends• Activity Feed, Live Stream f Introduction to Facebook PY API
  7. 7. Is That What You Want? f Introduction to Facebook PY API
  8. 8. Graph API Response Data Aggregate Information Access Token Request DataApplication Graph API Facebook Database • Facebook’s core • Social graph • Connections f Introduction to Facebook PY API
  9. 9. Graph Model• Composed of objects and connections• Identify entities and relationships by id• Data will be stored with smallest spaces and keep being updated f Introduction to Facebook PY API
  10. 10. Object Modelinformation from graph API without access token f Introduction to Facebook PY API
  11. 11. Graph Model information from graph API with access token f Introduction to Facebook PY API
  12. 12. 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 f Introduction to Facebook PY API
  13. 13. Connection Model f Introduction to Facebook PY API
  14. 14. Access to Graph• HTTP(S) Graph API• SDKs ‣ Javascript SDK ‣ iOS SDK ‣ Android SDK ‣ PHP SDK ‣ Python SDK f Introduction to Facebook PY API
  15. 15. HTTP(S) Graph API• RESTful HTTP request & response• Response data-type: JSON• Access URL: graph.facebook.com f Introduction to Facebook PY API
  16. 16. HTTP(S) Graph APIhttp://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 f Introduction to Facebook PY API
  17. 17. HTTP(S) Graph API http://graph.facebook.com/littleq0903Result: {      "id":  "1681390745",      "name":  "Colin  Su",      "first_name":  "Colin",      "last_name":  "Su",      "link":  "https://www.facebook.com/littleq0903",      "username":  "littleq0903",      "gender":  "male",      "locale":  "en_US" } f Introduction to Facebook PY API
  18. 18. 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 f Introduction to Facebook PY API
  19. 19. Get Access Token• GetMyAccess http://getmyaccess.heroku.com• It requires a permission called “offline_access”, so this token can be valid for a long time f Introduction to Facebook PY API
  20. 20. HTTP(S) Graph API• Access token should be transferred as a HTTP GET variablehttp://graph.facebook.com/littleq0903?access_token=...• More information: developers.facebook.com/docs/reference/ api/ f Introduction to Facebook PY API
  21. 21. Python SDK• Let you access all features of the Graph API• That’s all, let’s play! f Introduction to Facebook PY API
  22. 22. Python SDK• https://github.com/facebook/python-sdk• Designed to support Graph API and FB Javascript SDK (You will learn in the future) f Introduction to Facebook PY API
  23. 23. Graph• Depends your access token• Everyone will have their own graph, could be unique f Introduction to Facebook PY API
  24. 24. Graph API Class• Fetch the graph by implement it import  facebook graph  =  facebook.GraphAPI() user  =  graph.get_object(“littleq0903”) f Introduction to Facebook PY API
  25. 25. 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 different f Introduction to Facebook PY API
  26. 26. Graph Methods• get_object, get_objects• get_connections• put_object• put_wall_post, put_comment, put_like• delete_object f Introduction to Facebook PY API
  27. 27. Demo f Introduction to Facebook PY API
  28. 28. Homework• Fetch a kind of data on the FB Graph• Do some statistics on it• Don’t Copy from others f Introduction to Facebook PY API
  29. 29. Q&A TimeThanks for your listening f Introduction to Facebook PY API

×