Facebook API

A quick overview.

1 Overview

2 Authentication for Web Apps

  1. Get API key for your app, set the callback URL.
  1. Tell user to log into http://www.facebook.com/login.php?api_key=YOUR_API_KEY&v=1.0
  2. He is then taken to the callback URL with an appeded token: http://mycalback.com/url?auth_token=abc123
  3. Use this auth_token and send it to auth.createToken?api_key=YOUR_API_KEY&sig=MD5sig&v=1.0&auth_token=abc123 which will return a session_key and uid
  4. Use this session_key in all future requests. Use uid when needed.

3 Common Parameters

4 Methods

A few of the methods [8].
Admin.getAllocation [9]
Returns the current allocation limit for your application for the specified integration point.
Admin.getDailyMetrics [10]
Returns specified daily metrics for your application, given a date range.
admin.getAppProperties [11] (BETA)
Returns values of properties for your applications from the Facebook Developer application.
admin.setAppProperties [12] (BETA)
Sets values for properties for your applications in the Facebook Developer application.
application.getPublicInfo [13] (BETA)
Returns public information about a given application (not necessarily your own).
auth.createToken [14]
Creates an auth_token to be passed in as a parameter to login.php and then to auth.getSession after the user has logged in.
auth.getSession [15]
Returns the session key bound to an auth_token, as returned by auth.createToken [16] or in the callback URL.
batch.run [17] (BETA)
Execute a list of individual API calls in a single batch.
data.getCookies [18] (BETA)
Returns all cookies for a given user and application.
data.setCookie [19] (BETA)
Sets a cookie for a given user and application.
events.get [20]
Returns all visible events according to the filters specified.
events.getMembers [21]
Returns membership list data associated with an event.
fbml.refreshImgSrc [22]
Fetches and re-caches the image stored at the given URL.
fbml.refreshRefUrl [23]
Fetches and re-caches the content stored at the given URL.
fbml.setRefHandle [24]
Associates a given "handle" with FBML markup so that the handle can be used within the fb:ref [25] FBML tag.
feed.publishStoryToUser [26]
Publishes a News Feed story to the user corresponding to the session_key parameter.
feed.publishActionOfUser [27]
Publishes a Mini-Feed story to the user corresponding to the session_key parameter, and publishes News Feed stories to the friends of that user.
feed.publishTemplatizedAction [28]
Publishes a Mini-Feed story to the user or Page corresponding to the session_key or page_actor_id parameter.
fql.query [29]
Evaluates an FQL (Facebook Query Language) query.
friends.areFriends [30]
Returns whether or not each pair of specified users is friends with each other.
friends.get [31]
Returns the identifiers for the current user's Facebook friends.
friends.getAppUsers [32]
Returns the identifiers for the current user's Facebook friends who are signed up for the specific calling application.
friends.getLists [33]
Returns the identifiers for the current user's Facebook friend lists.
groups.get [34]
Returns all visible groups according to the filters specified.
groups.getMembers [35]
Returns membership list data associated with a group.
marketplace.createListing [36]
Create or modify a listing in Marketplace.
marketplace.getCategories [37]
Returns all the Marketplace categories.
marketplace.getListings [38]
Return all Marketplace listings either by listing ID or by user.
marketplace.getSubCategories [39]
Returns the Marketplace subcategories for a particular category.
marketplace.removeListing [40]
Remove a listing from Marketplace.
marketplace.search [41]
Search Marketplace for listings filtering by category, subcategory and a query string.
notifications.get [42]
Returns information on outstanding Facebook notifications for current session user.
notifications.send [43]
Sends a notification to a set of users.
notifications.sendRequest [44]
This method is disabled.
notifications.sendEmail [45]
Sends an email to the specified users who have the application.
pages.getInfo [46]
Returns all visible pages to the filters specified.
pages.isAdmin [47]
Checks whether the logged-in user is the admin for a given Page.
pages.isAppAdded [48]
Checks whether the Page has added the application.
pages.isFan [49]
Checks whether a user is a fan of a given Page.
photos.addTag [50]
Adds a tag with the given information to a photo.
photos.createAlbum [51]
Creates and returns a new album owned by the current session user.
photos.get [52]
Returns all visible photos according to the filters specified.
photos.getAlbums [53]
Returns metadata about all of the photo albums uploaded by the specified user.
photos.getTags [54]
Returns the set of user tags on all photos specified.
photos.upload [55]
Uploads a photo owned by the current session user and returns the new photo.
profile.setFBML [56]
Sets the FBML for a user's profile, including the content for both the profile box and the profile actions.
profile.getFBML [57]
Gets the FBML that is currently set for a user's profile.
users.getInfo [58]
Returns a wide array of user-specific information for each user identifier passed, limited by the view of the current user.
users.getLoggedInUser [59]
Gets the user ID (uid) associated with the current session.
users.hasAppPermission [60]
Checks whether the user has opted in to an extended application permission.
users.isAppAdded [61]
Returns whether the logged-in user has added the calling application.
users.setStatus [62]
Updates a user's Facebook status.

4.1 Friends.get

http://api.facebook.com/restserver.php?method=Frients.get&api_key=YOURKEY
&session_key=YOURSK&call_id=123&sig=MD5HASH&v=1.0
&format=XML
<?xml version="1.0" encoding="UTF-8"?>
<friends_get_response xmlns="http://api.facebook.com/1.0/" 
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
   xsi:schemaLocation="http://api.facebook.com/1.0/ http://api.facebook.com/1.0/facebook.xsd" 
  list="true">  
  <uid>222333</uid>  
  <uid>1240079</uid> 
</friends_get_response>


[222333,1240079]

4.2 Photos.get

http://api.facebook.com/restserver.php?method=Photos.get&api_key=YOURKEY
&session_key=YOURSK&call_id=123&sig=MD5HASH&v=1.0
&subj_id=USERID
&format=XML
<?xml version="1.0" encoding="UTF-8"?> 
<photos_get_response xmlns="http://api.facebook.com/1.0/" 
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
  xsi:schemaLocation="http://api.facebook.com/1.0/ http://api.facebook.com/1.0/facebook.xsd" 
  list="true">  
  <photo>  
    <pid>34585991612804</pid>  
    <aid>34585963571485</aid>  
    <owner>1240077</owner>  
    <src>http://ip002.facebook.com/v11/135/18/8055/s1240077_30043524_2020.jpg</src>  
    <src_big>http://ip002.facebook.com/v11/135/18/8055/n1240077_30043524_2020.jpg</src>  
    <src_small>http://ip002.facebook.com/v11/135/18/8055/t1240077_30043524_2020.jpg</src>  
    <link>http://www.facebook.com/photo.php?pid=30043524&id=8055</link>  
    <caption>From The Deathmatch (Trailer) (1999)</caption>  
    <created>1132553361</created>  
  </photo>  
  <photo>  
    <pid>34585991612805</pid>  
    <aid>34585963571485</aid>  
    <owner>1240077</owner>  
    <src>http://ip002.facebook.com/v11/135/18/8055/s1240077_30043525_2184.jpg</src>  
    <src_big>http://ip002.facebook.com/v11/135/18/8055/n1240077_30043525_2184.jpg</src>  
    <src_small>http://ip002.facebook.com/v11/135/18/8055/t1240077_30043525_2184.jpg</src>  
    <link>http://www.facebook.com/photo.php?pid=30043525&id=8055</link>  
    <caption>Mexico City, back cover of the CYHS Student Underground 1999.</caption>  
    <created>1132553362</created>  
  </photo> 
</photos_get_response>

5 Anatomy of an Application

You set your callback (URL) for each of these on the facebook website. They all require you to send back different markup.

6 FBML

7 FQL

SELECT name, affiliations FROM user
WHERE uid IN (SELECT uid2 FROM friend WHERE uid1=211031)
      AND "Facebook" IN affiliations.name AND uid < 10

SELECT src, caption, 1+2*3/4, caption, 10*(20 + 1) FROM photo
WHERE pid IN (SELECT pid FROM photo_tag WHERE subject=211031) AND
      pid IN (SELECT pid FROM photo_tag WHERE subject=204686) AND
      caption
Results in
<?xml version="1.0" encoding="UTF-8"?>
<fql_query_response xmlns="http://api.facebook.com/1.0/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://api.facebook.com/1.0/ http://api.facebook.com/1.0/facebook.xsd" list="true">
  <user>
    <name>Mark Zuckerberg</name>
    <affiliations list="true">
      <affiliation>
        <nid>50431648</nid>
        <name>Facebook</name>
        <type>work</type>
        <status/>
        <year/>
      </affiliation>
      <affiliation>
        <nid>16777217</nid>
        <name>Harvard</name>
        <type>college</type>
        <status>Undergrad</status>
        <year/>
      </affiliation>
      <affiliation>
        <nid>67108894</nid>
        <name>San Francisco, CA</name>
        <type>region</type>
        <status/>
        <year/>
      </affiliation>
    </affiliations>
  </user>
  <user>
    <name>Chris Hughes</name>
    <affiliations list="true">
      <affiliation>
        <nid>50431648</nid>
        <name>Facebook</name>
        <type>work</type>
        <status/>
        <year/>
      </affiliation>
      <affiliation>
        <nid>16777217</nid>
        <name>Harvard</name>
        <type>college</type>
        <status>Alumnus/Alumna</status>
        <year>2006</year>
      </affiliation>
      <affiliation>
        <nid>67108869</nid>
        <name>Washington, DC</name>
        <type>region</type>
        <status/>
        <year/>
      </affiliation>
      <affiliation>
        <nid>67108894</nid>
        <name>San Francisco, CA</name>
        <type>region</type>
        <status/>
        <year/>
      </affiliation>
    </affiliations>
  </user>
  <user>
    <name>Dustin Moskovitz</name>
    <affiliations list="true">
      <affiliation>
        <nid>50431648</nid>
        <name>Facebook</name>
        <type>work</type>
        <status/>
        <year/>
      </affiliation>
      <affiliation>
        <nid>16777217</nid>
        <name>Harvard</name>
        <type>college</type>
        <status>Undergrad</status>
        <year/>
      </affiliation>
      <affiliation>
        <nid>16777219</nid>
        <name>Stanford</name>
        <type>college</type>
        <status>Staff</status>
        <year/>
      </affiliation>
      <affiliation>
        <nid>67108894</nid>
        <name>San Francisco, CA</name>
        <type>region</type>
        <status/>
        <year/>
      </affiliation>
      <affiliation>
        <nid>67108896</nid>
        <name>Silicon Valley, CA</name>
        <type>region</type>
        <status/>
        <year/>
      </affiliation>
      <affiliation>
        <nid>67109006</nid>
        <name>Ocala, FL</name>
        <type>region</type>
        <status/>
        <year/>
      </affiliation>
    </affiliations>
  </user>
</fql_query_response>


<?xml version="1.0" encoding="UTF-8"?>
<fql_query_response xmlns="http://api.facebook.com/1.0/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://api.facebook.com/1.0/ http://api.facebook.com/1.0/facebook.xsd" list="true">
  <photo>
    <src>http://photos-923.ak.facebook.com/ip002/v61/188/75/206412/s206412_31508923_7923.jpg</src>
    <caption>celebrating 23 years of ari's life at the one and the oasis.</caption>
    <anon>2.5</anon>
    <caption>celebrating 23 years of ari's life at the one and the oasis.</caption>
    <anon>210</anon>
  </photo>
  <photo>
    <src>http://photos-447.ak.facebook.com/ip005/v40/164/17/202965/s202965_30849447_4635.jpg</src>
    <caption>Liar's Dice...</caption>
    <anon>2.5</anon>
    <caption>Liar's Dice...</caption>
    <anon>210</anon>
  </photo>
  <photo>
    <src>http://photos-480.ak.facebook.com/ip005/v29/188/75/206412/s206412_30452480_140.jpg</src>
    <caption>the crew. (RishDAWG!)</caption>
    <anon>2.5</anon>
    <caption>the crew. (RishDAWG!)</caption>
    <anon>210</anon>
  </photo>
  <photo>
    <src>http://photos-103.ak.facebook.com/ip001/v12/188/75/206412/s206412_30325103_6676.jpg</src>
    <caption>group photo!!!!</caption>
    <anon>2.5</anon>
    <caption>group photo!!!!</caption>
    <anon>210</anon>
  </photo>
  <photo>
    <src>http://photos-399.ak.facebook.com/ip001/v10/188/75/206412/s206412_30191399_9134.jpg</src>
    <caption>someone is particularly happy to be in this picture</caption>
    <anon>2.5</anon>
    <caption>someone is particularly happy to be in this picture</caption>
    <anon>210</anon>
  </photo>
  <photo>
    <src>http://photos-716.ak.facebook.com/ip007/v16/129/99/204686/s204686_30190716_7256.jpg</src>
    <caption>One of the most extravagant.</caption>
    <anon>2.5</anon>
    <caption>One of the most extravagant.</caption>
    <anon>210</anon>
  </photo>
</fql_query_response>

8 Conclusion

URLs

  1. Facebook developers, http://developers.facebook.com
  2. API documentation, http://wiki.developers.facebook.com/index.php/API
  3. f8 keynote, http://developers.facebook.com/videos.php
  4. wikipedia:Representational_State_Transfer, http://www.wikipedia.org/wiki/Representational_State_Transfer
  5. facebook.xsd, http://api.facebook.com/1.0/facebook.xsd
  6. authentication guide, http://wiki.developers.facebook.com/index.php/Authentication_guide
  7. JSONP, http://bob.pythonmac.org/archives/2005/12/05/remote-json-jsonp/
  8. methods, http://wiki.developers.facebook.com/index.php/API
  9. Admin.getAllocation, http://wiki.developers.facebook.com/index.php/Admin.getAllocation
  10. Admin.getDailyMetrics, http://wiki.developers.facebook.com/index.php/Admin.getDailyMetrics
  11. Admin.getAppProperties, http://wiki.developers.facebook.com/index.php/Admin.getAppProperties
  12. Admin.setAppProperties, http://wiki.developers.facebook.com/index.php/Admin.setAppProperties
  13. Application.getPublicInfo, http://wiki.developers.facebook.com/index.php/Application.getPublicInfo
  14. Auth.createToken, http://wiki.developers.facebook.com/index.php/Auth.createToken
  15. Auth.getSession, http://wiki.developers.facebook.com/index.php/Auth.getSession
  16. Auth.createToken, http://wiki.developers.facebook.com/index.php/Auth.createToken
  17. Batch.run, http://wiki.developers.facebook.com/index.php/Batch.run
  18. Data.getCookies, http://wiki.developers.facebook.com/index.php/Data.getCookies
  19. Data.setCookie, http://wiki.developers.facebook.com/index.php/Data.setCookie
  20. Events.get, http://wiki.developers.facebook.com/index.php/Events.get
  21. Events.getMembers, http://wiki.developers.facebook.com/index.php/Events.getMembers
  22. Fbml.refreshImgSrc, http://wiki.developers.facebook.com/index.php/Fbml.refreshImgSrc
  23. Fbml.refreshRefUrl, http://wiki.developers.facebook.com/index.php/Fbml.refreshRefUrl
  24. Fbml.setRefHandle, http://wiki.developers.facebook.com/index.php/Fbml.setRefHandle
  25. Fb:ref, http://wiki.developers.facebook.com/index.php/Fb:ref
  26. Feed.publishStoryToUser, http://wiki.developers.facebook.com/index.php/Feed.publishStoryToUser
  27. Feed.publishActionOfUser, http://wiki.developers.facebook.com/index.php/Feed.publishActionOfUser
  28. Feed.publishTemplatizedAction, http://wiki.developers.facebook.com/index.php/Feed.publishTemplatizedAction
  29. Fql.query, http://wiki.developers.facebook.com/index.php/Fql.query
  30. Friends.areFriends, http://wiki.developers.facebook.com/index.php/Friends.areFriends
  31. Friends.get, http://wiki.developers.facebook.com/index.php/Friends.get
  32. Friends.getAppUsers, http://wiki.developers.facebook.com/index.php/Friends.getAppUsers
  33. Friends.getLists, http://wiki.developers.facebook.com/index.php/Friends.getLists
  34. Groups.get, http://wiki.developers.facebook.com/index.php/Groups.get
  35. Groups.getMembers, http://wiki.developers.facebook.com/index.php/Groups.getMembers
  36. Marketplace.createListing, http://wiki.developers.facebook.com/index.php/Marketplace.createListing
  37. Marketplace.getCategories, http://wiki.developers.facebook.com/index.php/Marketplace.getCategories
  38. Marketplace.getListings, http://wiki.developers.facebook.com/index.php/Marketplace.getListings
  39. Marketplace.getSubCategories, http://wiki.developers.facebook.com/index.php/Marketplace.getSubCategories
  40. Marketplace.removeListing, http://wiki.developers.facebook.com/index.php/Marketplace.removeListing
  41. Marketplace.search, http://wiki.developers.facebook.com/index.php/Marketplace.search
  42. Notifications.get, http://wiki.developers.facebook.com/index.php/Notifications.get
  43. Notifications.send, http://wiki.developers.facebook.com/index.php/Notifications.send
  44. Notifications.sendRequest, http://wiki.developers.facebook.com/index.php/Notifications.sendRequest
  45. Notifications.sendEmail, http://wiki.developers.facebook.com/index.php/Notifications.sendEmail
  46. Pages.getInfo, http://wiki.developers.facebook.com/index.php/Pages.getInfo
  47. Pages.isAdmin, http://wiki.developers.facebook.com/index.php/Pages.isAdmin
  48. Pages.isAppAdded, http://wiki.developers.facebook.com/index.php/Pages.isAppAdded
  49. Pages.isFan, http://wiki.developers.facebook.com/index.php/Pages.isFan
  50. Photos.addTag, http://wiki.developers.facebook.com/index.php/Photos.addTag
  51. Photos.createAlbum, http://wiki.developers.facebook.com/index.php/Photos.createAlbum
  52. Photos.get, http://wiki.developers.facebook.com/index.php/Photos.get
  53. Photos.getAlbums, http://wiki.developers.facebook.com/index.php/Photos.getAlbums
  54. Photos.getTags, http://wiki.developers.facebook.com/index.php/Photos.getTags
  55. Photos.upload, http://wiki.developers.facebook.com/index.php/Photos.upload
  56. Profile.setFBML, http://wiki.developers.facebook.com/index.php/Profile.setFBML
  57. Profile.getFBML, http://wiki.developers.facebook.com/index.php/Profile.getFBML
  58. Users.getInfo, http://wiki.developers.facebook.com/index.php/Users.getInfo
  59. Users.getLoggedInUser, http://wiki.developers.facebook.com/index.php/Users.getLoggedInUser
  60. Users.hasAppPermission, http://wiki.developers.facebook.com/index.php/Users.hasAppPermission
  61. Users.isAppAdded, http://wiki.developers.facebook.com/index.php/Users.isAppAdded
  62. Users.setStatus, http://wiki.developers.facebook.com/index.php/Users.setStatus
  63. Friends.get, http://wiki.developers.facebook.com/index.php/Friends.get
  64. Photos.get, http://wiki.developers.facebook.com/index.php/Photos.get
  65. different pages, http://wiki.developers.facebook.com/index.php/Anatomy_of_a_Facebook_App
  66. , http://wiki.developers.facebook.com/index.php/Anatomy_of_a_Facebook_App#Application_Directory
  67. , http://wiki.developers.facebook.com/index.php/Anatomy_of_a_Facebook_App#About_Page
  68. , http://wiki.developers.facebook.com/index.php/Anatomy_of_a_Facebook_App#Left_Nav
  69. , http://wiki.developers.facebook.com/index.php/Anatomy_of_a_Facebook_App#Facebook_Canvas_Pages
  70. , http://wiki.developers.facebook.com/index.php/Anatomy_of_a_Facebook_App#Profile
  71. , http://wiki.developers.facebook.com/index.php/Anatomy_of_a_Facebook_App#Privacy_Settings
  72. , http://wiki.developers.facebook.com/index.php/Anatomy_of_a_Facebook_App#News_Feed
  73. , http://wiki.developers.facebook.com/index.php/Anatomy_of_a_Facebook_App#Alerts
  74. , http://wiki.developers.facebook.com/index.php/Anatomy_of_a_Facebook_App#Message_Attachments
  75. , http://wiki.developers.facebook.com/index.php/Anatomy_of_a_Facebook_App#Requests
  76. , http://wiki.developers.facebook.com/index.php/Anatomy_of_a_Facebook_App#Interacting_with_Users
  77. Facebook Markup Language, http://wiki.developers.facebook.com/index.php/FBML
  78. http://wiki.developers.facebook.com/index.php/Fb:name
  79. fb:is-in-network, http://wiki.developers.facebook.com/index.php/Fb:is-in-network
  80. http://wiki.developers.facebook.com/index.php/Fb:editor
  81. Faceebook query language, http://developers.facebook.com/documentation.php?doc=fql
  82. Google gadgets, http://www.google.com/webmasters/gadgets/
  83. love the traffic, http://blog.pmarca.com/2007/06/analyzing_the_f.html
  84. OpenSocial, http://code.google.com/apis/opensocial/
  85. better, http://blog.pmarca.com/2007/10/open-social-a-n.html
  86. Internet platform, http://blog.pmarca.com/2007/09/the-three-kinds.html

This talk available at http://jmvidal.cse.sc.edu/talks/facebook/
Copyright © 2009 José M. Vidal . All rights reserved.

14 April 2008, 02:15PM