Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member
Facebook stores information about users and their connections in something known as the Social Graph. It's sometimes also called the Open Graph. To access that data, Facebook provides something called the Open Graph API. In the previous video we learned how to access data about the user by using a path called /me, which is a shortcut to the current user. Let's take a look at how to use other paths to get different types of information from Facebook. The paths we're using /me looks suspiciously like the end of URL, and it is.
Facebook takes our path and sends it to an application at graph.facebook.com, so we can use that URL with different paths to get some public information about the Facebook object, plus, we can also build our own paths. If you take a look at the API Reference, you can see some examples of other paths you can use to retrieve data. If you click on one of these URLs, you'll see the results displayed as JSONobjects, which are similar to PHP associative arrays. So we can use the username of any existing Facebook account and get some basic data about that user.
We could use a username stuart.beland, and we would get the info for our current Facebook user. Now instead of the User Name, we can also use a User ID, so I'm going to grab the User ID from our application and then come over here and just paste that right there. So if you know your User ID or your User Name, you can try that as a call to graph.facebook.com. If you look at the rest of this list, there is a lot of different information we can get from other pages, so this, for example is a Coca-Cola page, and you can see some generic information here from a page, instead of a user.
There's a link to groups, photos, photo albums, and other things you can get from the Graph API. In addition to accessing objects, we can also access an object connection, you can see that there are paths here for different things, like friends, a profile or a wall, likes, books, et cetera. Now these paths to connections require access tokens or permissions, you can't just do this with any user, but at least on this page you can explore some of them. As long as you have permissions to get this user data, you can use these in your applications as well.
You don't always need to get all of the information from a user, you can also limit the fields the call returns. So let me try a page I created for BarCamp event in my area. Now we can limit the fields by passing along the field variables with a value and a description, so I'm going to add a question mark here and just type in the fields that I want. That sometimes makes it easier to get just the information we need and reduces the overall size of the data we retrieve. You can also ask for information from multiple IDs, like more than one user.
To get a clear understanding of how to work with each object and its connection, take a look at the left side of the Graph API Reference, each object is listed there. If you click on an object you can see its permission requirements. To read the photo object we need a valid access token, as well as the user photos permission, if we want to access photos and albums uploaded by a user, as well as the friends_photos permissions to access their friend's photos and photos in which the user has been tagged. You can also publish a photo if you have a publish stream permission.
These are all permissions that you can ask for in your applications, you can also see a list of all the fields you can get from that data and types of connections, as well as ways to create and do things like delete some of these objects. Paths are a really powerful way to access data inside the Open Graph, any developer that has used a HTTP post or get methods should be able to pick up the syntax in no time.
Get unlimited access to all courses for just $25/month.Become a member
61 Video lessons · 100214 Viewers
56 Video lessons · 113200 Viewers
71 Video lessons · 82084 Viewers
131 Video lessons · 39385 Viewers
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.