Skip to main content
The GraphRequest class represents a single request to the Facebook Graph API and provides support for batch requests through GraphRequestManager.

Import

Constructor

string
required
The Graph API endpoint to call (e.g., “me”, “me/friends”, “12345/posts”).
GraphRequestConfig
Optional configuration for the request including HTTP method, API version, parameters, and access token.
GraphRequestCallback
Function called when the request completes or fails.

Properties

graphPath

The Graph API endpoint for this request.

config

The configuration object for this request.

callback

The completion callback for this request.

Methods

addStringParameter

Adds a string parameter to the request.
string
required
The parameter value.
string
required
The parameter key.

Usage Examples

Simple GET Request

GET Request with Parameters

POST Request

Request with Custom Access Token

Using addStringParameter

Fetch User Friends

Fetch User Photos

TypeScript Types

GraphRequestConfig

Configuration object for Graph API requests.

GraphRequestParameters

Parameters for Graph API requests.
When setting parameters, wrap values in an object with a string property:

GraphRequestCallback

Callback function for handling request results.
Record<string, unknown>
Error object if the request failed, undefined otherwise.
Record<string, unknown>
Response data if the request succeeded, undefined otherwise.

Best Practices

  1. Always handle errors in your callback function
  2. Use specific field selectors to request only the data you need
  3. Specify API version in config for consistent behavior
  4. Batch multiple requests using GraphRequestManager for better performance
  5. Check Graph API documentation for available endpoints and parameters