Facebook Technologies: Proprietary / Using the Facebook API
Visitors to VTC.com will be able to view all introductory videos for each training course.
Free Trial Members will gain access to first three chapters for each training course.
Full Access Members have full access to VTC.com’s entire library of video tutorials.
Learn More
Subtitles of the Movie
Now you've seen how to use FBML to create objects, retrieve data from the database and exercise control in case someone is a user of the application or isn't. But there's another major component that we use which is the Facebook API and I've referred to it several times. Now I'll take a look at the syntax of it. The Facebook API is referred to using the REST client so Facebook is the object that I create at the beginning of almost every file. Within that is an API client, sometimes called the REST client that does the actual communicating back and forth with Facebook and this is the method in the API client that I'm going to call and it will be called by the client. The communication is set up so the parameters that I pass in, if any, to the method inside the client are then passed back to Facebook. A result, which is almost always XML comes back to the API client and the API client then translates that back into something such as init Array, which I can use. Now, the information about the Facebook API is here in the documentation, not in the FBML section but in the API section. So I come up here and this is a list of all the methods that are available to me through the Facebook API. They're in various sections, for example and you can see from the first word what section they're in. I can find information about users, all sorts of information here and it's communicated not through FBML but by calling that method inside the REST library of the Facebook application. Then I go directly into these routines. Now, it will probably not surprise you that just as I have an FBML Test Console, I have an API Test Console and let's take a look at that. The API Test Console is very similar to the FBML Test Console. What I do is it's already filled in my user ID, assuming that I'm logged into Facebook and down here I have a list of all of the methods that I can call. In this case what I want to do is call Friends.get. This will provide me with a list of all of the friends for this user ID that I'm logged in as. There are three response formats that you can choose from. What usually comes back from the API call is XML but it can be translated back into JSON format or the format that you're going to get back in your application that is calling the PHP client. So for example, this is a slightly different method that's being called but inside the PHP client, this is what I'm going to get back. So let me take a look if I just call the Friends.get method for the PHP client. What I'm going to get back is an Array, the zeroth element is one user ID of the first friend. The first element, which is the second in the Array is the user ID of the second friend. If I ask for the information in JSON format, I'm doing the same call and I just get back the two ids separated by commas. What is actually coming back underneath all of this is XML and the API client is parsing that XML into one of the other two formats depending on what I want to do with it. So you can test any of these methods using the API Test Console and you can examine the results. As you're developing, you may want to see what the values are to make certain that you're picking them up properly and you can, of course, copy this code and paste it into your application once you have refined what it is you're, you're using. So that's a very brief summary of the API calls. They're quite straightforward and you don't have to write a great deal of code for them because all of the encoding and decoding is done for you by the API client.
Tutorial Information
| Course: | Facebook Application Development |
| Author: | Jesse Feiler |
| SKU: | 34058 |
| ISBN: | 1-935320-81-5 |
| Release Date: | 2009-11-23 |
| Duration: | 7.5 hrs / 92 lessons |
| Work Files: |
Yes |
| Captions: | Available on CD and Online University |
| Compatibility: |
Vista/XP/2000, OS X, Linux QuickTime 7, Flash 8 |
VTC Sign up & Benefits
- Unlimited Access
- 98,729 Video Tutorials (23,265 free)
- Video Available as Flash or QuickTime
- Over 1026 Courses
- $30 for One Month Access
- Multi-User Discounts Available
United States 