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
- Always handle errors in your callback function
- Use specific field selectors to request only the data you need
- Specify API version in config for consistent behavior
- Batch multiple requests using
GraphRequestManagerfor better performance - Check Graph API documentation for available endpoints and parameters
Related
- GraphRequestManager - Execute single or batch requests
- Facebook Graph API Documentation