The Graph API is the primary way to get data into and out of the Facebook platform.
Useful tools: open_in_new Graph API Explorer .
Docs
Facebook recommends starting with these guides:
Also useful: open_in_new Access token documentation .
Terminology
The Graph API is named after the idea of a “social graph” — a representation of the information on Facebook. It is composed of:
- nodes — individual objects, such as a User, a Photo, a Page, or a Comment;
- edges — connections between a collection of objects and a single object, such as Photos on a Page or Comments on a Photo;
- fields — data about an object, such as a User’s birthday or a Page’s name.
Typically you use nodes to get data about a specific object, edges to get collections of objects on a single object, and fields to choose which data is included in responses.
In short:
- use nodes to get data about individual objects;
- use edges to get collections of objects connected to a node, or to publish objects to those collections;
- use fields to specify which data you want in responses.
Host URL
Almost all requests go to graph.facebook.com. The single exception is video uploads, which use graph-video.facebook.com.
Request structure
These two forms are equivalent:
GET /comments?id=3078780142147466&summary=1&filter=stream&fields=id,from,message,created_time,parent
GET /3078780142147466/comments?summary=1&filter=stream&fields=id,from,message,created_time,parent
Object IDs
Nodes are individual objects, each with a unique ID, so to get information about a node you query its ID directly. For example, every Facebook Page or User account has an ID:
curl -i -X GET \
"https://graph.facebook.com/object-id
?access_token=your-access-token"
You can usually delete a node with a DELETE on the object ID:
curl -i -X DELETE \
"https://graph.facebook.com/object-id
?access_token=your-access-token"
Note: Running a DELETE against your own user ID can delete your Facebook User account.
Nodes list
open_in_new Graph API reference .
SDK
- PHP library: open_in_new facebook/php-graph-sdk
- Examples: open_in_new sohaibilyas/facebook-php-graph-sdk-examples
Andrew Dorokhov