tbs Barney Style Solutions Graph API ad (1)

Graph API Components

Overview of the Graph API Components

A brief walkthrough of the Graph API components

If you want to read and write data on Facebook’s platform, then you have to use the Graph API. Because it is HTTP-based, you can use it to query data, post stories, manage ads, upload photos, and perform a multitude of other tasks.  Creative developing will help you plan the best use of the API calls you make.

The fundamental components of the Graph API are nodes, edges, and fields. Nodes are single objects. Edges are connections between a collection of objects and an object. Fields are an object’s data. Knowing how each component interacts with the other component will allow you to write smart APIs for your apps.

Nodes are individual objects with unique IDs. Access to a node is gained through the unique id given to a node. Examples of nodes are, comments, pictures, pages, or users. Here is an example on how to query data about a facebook user through their unique user ID.

curl -i -X GET \
 “https://graph.facebook.com/object-id?access_token=your-access-token”

The access_token parameter is usually, but now always required to complete your requests. Nodes can be deleted using the DELETE method.

curl -i -X DELETE \
 “https://graph.facebook.com/object-id?access_token=your-access-token”

Edges are the connections between a collection of objects and another object (i.e. photos on a page or comments on a photo). If you want a collection of objects connected to a single object, you would use the edges components when querying data. Think about using the edges component when you want to do things like get all the pictures of a certain user. Most nodes have edges that return a collection of objects related to a node. The post edge is a collection of post objects related to a single node, like user. Below is an example of how to use such an edge in your GET query

curl -i -X GET \
 “https://graph.facebook.com/your-facebook-user-id/posts?access_token=your-access-token”

Fields are the data value on each node. Fields get information about a specific objet or each object in a collection. Think about using fields as a way to get a value on a particular category like, date, name, etc. Fields specify the parameters you want returned in a response. Her’s an example of using the name field in a response

curl -i -X GET \
“https://graph.facebook.com/your-facebook-user-id?fields=name&access_token=your-access-token”

Some nodes give you the ability to update their field data with the POST method. Just remember that you’ll need the special access token that grants you specific authority to update the corresponding field. Below is an example of updating a field via POST.

curl -i -X POST \”https://graph.facebook.com/your-facebook-user-id?email=you@your-email.com&access_token=your-access-token”

There are different versions of the Graph API. You can envoke the version you prefer when you make your call. Take a look at how the following call envokes v2.9

curl -i -X GET \”https://graph.facebook.com/v2.9/your-facebook-user-id/photos?access_token=your-access-token”

Make sure to include the version number in your request, or else the call will default to the oldest version.  More information on the versions can be found in the version change log or the reference docs section of fb developer docs.