Before you start
- Get an API keySign up for 100 free credits, no card. Keys start with
gs_live_. - Put it in the environmentEvery example reads it from
GROUNDSOCIAL_API_KEY:export GROUNDSOCIAL_API_KEY=gs_live_… - Set up PHP
php -m | grep curl # the curl extension ships with most PHP builds
Call Facebook post API from PHP
GET /v1/facebook/posts. Save this as main.php and run php main.php. It prints message and comment_count.
<?php
function groundsocial(string $path, array $params = []): array
{
$url = 'https://api.groundsocial.dev' . $path . ($params ? '?' . http_build_query($params) : '');
$ch = curl_init($url);
curl_setopt_array($ch, [
CURLOPT_HTTPHEADER => ['Authorization: Bearer ' . getenv('GROUNDSOCIAL_API_KEY')],
CURLOPT_RETURNTRANSFER => true,
CURLOPT_TIMEOUT => 60,
]);
$raw = curl_exec($ch);
$status = curl_getinfo($ch, CURLINFO_RESPONSE_CODE);
curl_close($ch);
$data = json_decode($raw, true);
if ($status !== 200) {
$e = $data['error'];
throw new RuntimeException($e['code'] . ': ' . ($e['hint'] ?? $e['message']));
}
return $data;
}
$data = groundsocial('/v1/facebook/posts', ['url' => 'https://www.facebook.com/zuck/posts/pfbid0Cj47VyownRywjfYupyWgyDKSmv3bFUDRWLpwjDzPZdF2mFfRMTWkyMS3vVRo5reyl']);
echo $data['message'], ' ', $data['comment_count'], PHP_EOL;The response
A real Facebook response to this call, recorded from the live source and shortened for display: arrays keep their first items and … marks every cut. Live calls return current data in the same shape.
{
"post_id": "10118155444854771",
"id": "UzpfSTQ6MTAxMTgxNTU0NDQ4NTQ3NzE6MTAxMTgxNTU0NDQ4NTQ3NzE=",
"feedback_id": "ZmVlZGJhY2s6cGZiaWQwQ2o0N1Z5b3duUnl3amZZdXB5V2d5REtTbXYzYkZVRFJXTHB3akR6UFpkRjJtRmZSTVRXa3lNUzN2VlJvNXJleWw=",
"url": "https://www.facebook.com/zuck/posts/pfbid0Cj47VyownRywjfYupyWgyDKSmv3bFUDRWLpwjDzPZdF2mFfRMTWkyMS3vVRo5reyl",
"creation_time": 1793554070,
"message": "Tried to get the family to dress as burger night, but couldn't corral the littlest burger",
"author": {
"id": "4",
"name": "Mark Zuckerberg",
"url": "https://www.facebook.com/zuck"
},
"attachments": [
{
"media": {
"__typename": "Photo",
"__isNode": "Photo",
"id": "10118155440653191"
},
"styles": {
"__typename": "StoryAttachmentAlbumStyleRenderer",
"__isStoryAttachmentStyleRendererUnion": "StoryAttachmentAlbumStyleRenderer",
"is_prod_eligible": true,
"attachment": {
"mediaset_token": "pcb.10118155444854771",
"url": "https://www.facebook.com/zuck/posts/pfbid0Cj47VyownRywjfYupyWgyDKSmv3bFUDRWLpwjDzPZdF2mFfRMTWkyMS3vVRo5reyl",
"all_subattachments": {
"count": 3,
"nodes": [
"…"
]
},
"comet_product_tag_feed_overlay_renderer": null
},
"__module_operation_CometFeedStoryAttachmentMatchRenderer_attachment": {
"__dr": "CometFeedStoryAlbumAttachmentStyle_styleTypeRenderer$normalization.graphql"
},
"__module_component_CometFeedStoryAttachmentMatchRenderer_attachment": {
"__dr": "CometFeedStoryAlbumAttachmentStyle.react"
}
}
}
],
"reaction_count": 228529,
"comment_count": 28701,
"share_count": 6825,
"video_view_count": null,
"top_comments": [
{
"id": "Y29tbWVudDoxMDExODE1NTQ0NDg1NDc3MV8xMTk4OTc5MTI5NTMwNzE0",
"text": "What does a human burger taste like? 😉",
"created_time": 1793558085,
"author": {
"id": "pfbid021StH2n3mR7TLVbLXnWPjqVdsugKkZsoiqacTjoP7PmA5oafkXG2BPXBHyTgfGsZsl",
"name": "Hassan Hafez",
"url": null
}
},
{
"id": "Y29tbWVudDoxMDExODE1NTQ0NDg1NDc3MV8xMDU4MTYwMTkwNTk0NTEy",
"text": "You all could have done the characters from Burger Time 😄",
"created_time": 1793560720,
"author": {
"id": "pfbid02iz4RhdW3FTRS4LgtRhPWYWpXqYx1dEuVKVc7AvVMtxSMyrDhgoNfbig8UqMLU4J8l",
"name": "Teri Mut",
"url": null
}
},
"… 8 more"
]
}Top-level fields
| Field | Type | Description |
|---|---|---|
post_id | string | – |
id | string | null | Facebook’s opaque node id for the story. |
feedback_id | string | null | Pass to facebook_post_comments to page through every comment. |
url | string | – |
creation_time | integer | null | Published, Unix seconds (UTC). |
message | string | null | – |
author | object | null | – |
attachments | object[] | Facebook’s attachments: photos, the video (with media.id), links. |
reaction_count | integer | null | – |
comment_count | integer | null | – |
share_count | integer | null | – |
video_view_count | integer | null | – |
top_comments | object[] | The few top comments a logged-out visitor sees. |
Parameters
| Name | In | Type | Description |
|---|---|---|---|
url (required) | query | string | The post URL. Example: https://www.facebook.com/zuck/posts/pfbid0Cj47VyownRywjfYupyWgyDKSmv3bFUDRWLpwjDzPZdF2mFfRMTWkyMS3vVRo5reyl. |
Errors and retries
Every error is JSON with error.code (stable: branch on it), message, hint (what to do next), docs_url and retryable. A failed call is never charged. Retry only when retryable is true, after the Retry-After header.
try {
$data = groundsocial('/v1/facebook/posts', ['url' => 'https://www.facebook.com/zuck/posts/pfbid0Cj47VyownRywjfYupyWgyDKSmv3bFUDRWLpwjDzPZdF2mFfRMTWkyMS3vVRo5reyl']);
} catch (RuntimeException $e) {
// "code: hint", e.g. "target_not_found: ..." (never charged).
fwrite(STDERR, $e->getMessage() . PHP_EOL);
exit(1);
}| Status | Meaning |
|---|---|
200 | The post. |
400 | Invalid input. Nothing was charged. |
401 | Missing or invalid API key. |
402 | Not enough credits, a spend cap was reached, or payment is required. |
403 | The target is private, or the account is suspended. |
404 | The ad, Page or advertiser is not in the Meta Ad Library. |
429 | Too many requests. Wait for Retry-After seconds. |
503 | Facebook is temporarily unavailable. Retryable; nothing was charged. |
Every error code and what to do about it.
Pricing
| Cost | |
|---|---|
| Per call | 2 credits per call |
| 1,000 calls | $2.00 on the starter pack, $0.80 at volume |
| No key (MPP or x402) | $0.02 per call |
| Failed call | Refunded, never charged |
Every response has x-credits-charged and x-credits-remaining headers. Credits never expire. Packs and calculator.
From an AI agent (MCP)
The same call is the facebook_post_get tool on the hosted MCP server, so Claude, Cursor or any MCP client can make it without code. Add the server once:
claude mcp add --transport http groundsocial https://api.groundsocial.dev/mcpThen ask for it in words (“A public Facebook post: message, author, attachments, reactions, comments, shares, views, top comments”), or call the tool directly:
{
"jsonrpc": "2.0",
"id": 1,
"method": "tools/call",
"params": {
"name": "facebook_post_get",
"arguments": {
"url": "https://www.facebook.com/zuck/posts/pfbid0Cj47VyownRywjfYupyWgyDKSmv3bFUDRWLpwjDzPZdF2mFfRMTWkyMS3vVRo5reyl"
}
}
}MCP setup for Claude Desktop, Cursor, VS Code and ChatGPT.
Measure a post
Store reaction_count, comment_count, share_count and video_view_count hourly to chart how a post performs.
Keep going
- This call in Python, JavaScript, TypeScript, Go, cURL.
- Facebook post API reference: every field and status code.
- Facebook tutorials and all PHP tutorials.
- Facebook API: every endpoint and price.
- How to scrape Facebook Marketplace listing with PHP: One Facebook Marketplace listing: price, description, location, attributes, photos.
- How to scrape Facebook event with PHP: A public Facebook event: when, venue, description, hosts, tickets, responses.
- How to scrape Facebook Ad Library search with PHP: Search the Meta Ad Library by keyword: 30 ads a page with country, status, media, category, language, placement and date filters.
- How to scrape Facebook Ad Library company ads with PHP: Every ad of one advertiser (Facebook Page) in the Meta Ad Library, 30 a page, filterable.
- How to scrape Facebook Ad Library advertiser search with PHP: Find advertisers (Facebook Pages) in the Meta Ad Library by name.
- How to scrape Facebook Ad Library advertiser profile with PHP: An advertiser’s Meta Ad Library profile: Page and Instagram details, political spend, top ad.
Run it on your own data
One key for Facebook and 76 more platforms, over REST or MCP. Free credits on signup, no card.
Facebook is a trademark of Meta Platforms, Inc. We are not affiliated with or endorsed by Meta.