Start learning with our library of video tutorials taught by experts. Get started
Viewed by members. in countries. members currently watching.
Learn the basics of building complex, data-driven applications with the Facebook PHP SDK and MySQL. Author Ray Villalobos first introduces the fundamentals, such as checking to see if a user is logged into an application, accessing Facebook user data through the Open Graph API, and making complex API calls with the Graph API Explorer. The course then dives into building an application with API paths and Facebook Query Language (FQL) calls. Along the way, you'll discover how to post to a user's wall, upload photos, integrate with webpages, and more.
The Graph API allows you to search through a user's graph data by creating a path to a user's account, but you can also use sub paths to look through a user's connection. You can build more complicated queries by using limits and also making sub queries. Let's take a look at what it takes to make a really complex connection to the Open Graph. So, I have the Open Graph API Explorer already open and by default it's creating a path for me with this user's ID, as well as calling two fields ID and Name. In your apps, you're probably going to be using the path /me to get the graph of the current user, you can do that in here too. You can also of course use the ID of any object.
If you want to find out about connections, then you've got a couple of options, you can click on the plus sign and choose a connection. At first you'll see this field section, if you scroll down you'll see connections, let's go ahead and pick friends, and I'll hit Submit, and I'll get a list of the user's friends. You can also see that friend was added to the list of fields in the path. The second way to do this is by just adding /friends as part of the path to get directly to a user's friends.
Sometimes it's a little bit cleaner to have access to specific connections, like with the previous path, the Graph API is going to return the name, as well as an ID for each user. We can request additional fields if you like, so let's add movies from the list of connections, and I'll hit Submit. Notice that the Graph API sometimes returns more things then you're asking for, so for example, when we request that movies, it's also returning category as well as the created time, you can limit the amount of results by adding a limit field.
From this pop-up list, I'll select limit, and type in a number, say 3. This is going to limit not the amount of movies, but the amount of friends that are being listed. So here you have one friend, another friend, and another friend. To display additional results, you can also use the offset variable, I can just type that one in, that's going to allow me to see the next three users. This will allow you to create additional pages of results in your applications.
Let's say that now instead of limiting the amount of friends, you wanted to limit the amount of movies each friend has shared with you, you could do that by adding the limit command to the movies field. Notice that there is a plus sign inside of the movies field, so if I click on that and select limit, I can type in a limit for the amount of movies that I want each result to generate, so I'll select 2, hit Submit, and now I'm only getting two movies right here. Notice that some of these friends haven't recommended any movies, but they still appear as part of this query.
Let's go ahead and add the name of the friends so it's a little clear. So you can see the user Cecilia Largo hasn't recommended any movies. Now within the movies you also have access to subfields, if you click on this plus sign you can see that the fields are now different than they used to be. They have things like awards, directed_by, name, plot_outline, and other things. Let's go ahead and add some subfields to the movies. You can choose them from this pop-up list or if you know him just type them in.
Take a look at what it's doing here, it's adding dots to the movies and adding additional commands. One of the commands is limit(2) and the other one is fields and in there I can type in the additional fields I want, and I'll hit Submit. So now I can see the movies ID, as well as the name, a link to a picture, as well as a link to the page that the user had liked to get this in their profile. I also added a description and a number of likes that tells you how popular this movie is based on how many people have liked this page.
These parentheses also let you go inside individual fields and pass additional attributes. Take, for example, the image we get back, we asked for an image link, and it's given us a URL right here. We can pass some parameters requesting that the image be a certain size. Now I'm going to hold down the Command key and click on this image, so it'll appear in a new tab. So when I click on that, you'll see that we requested a 100x100 pixel image, and it tries as best as it can to give you an image of that size.
If somebody has uploaded a smaller image, it'll just give you whatever image you have. So you may have to develop some CSS just scale up or down any images that are too big too small, it's a good idea to include a width and a height parameter just to make sure we limit the pictures to the size that we want. By default, some pictures will be a certain width, and whatever height the user use, to upload the image. So you can see that by adding some periods and parentheses, we can really get very detailed in how we construct the path. They can get quite complex, but they're pretty much like passing a string via a get command on a form.
Once you get the hang of the syntax, you can perform some pretty complex queries into the open Graph API.
There are currently no FAQs about Building Facebook Applications with PHP and MySQL.
Access exercise files from a button right under the course name.
Search within course videos and transcripts, and jump right to the results.
Remove icons showing you already watched videos if you want to start over.
Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.
Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.