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 Python
pip install requests
Call Facebook comment replies API from Python
GET /v1/facebook/comments/replies. Save this as main.py and run python main.py. It reads the items in comments and prints text and reply_count for each.
import os
import requests
API = "https://api.groundsocial.dev"
HEADERS = {"Authorization": f"Bearer {os.environ['GROUNDSOCIAL_API_KEY']}"}
res = requests.get(
f"{API}/v1/facebook/comments/replies",
params={"feedback_id": "ZmVlZGJhY2s6cGZiaWQwRlZTRW0yQlNpUFl3VmhDbTZheUJiSGcza2I3N2lYMUg2ZExhYTFKTXk4N3J1TUJKa2c0Z1o4dkNIWjl6bVJ3ZURycmtvRE5yOWZMWmpFQThudDlrSFR2QWI3UEd1a3VaNWlmMWw=", "expansion_token": "MjoxNzk1NTkyMjgxOgF_P6SokemgwnbmUm5tQd9IrppVFms8FLfDsfypSPQAraQFTmutXExMPBwM2bAJqkdJGGFkJ1sXM1E2Yog1SoEcGwT04mrhQrb_pUnkLq-ZnquWHXTCWcMAcuMoANUBH8V3MFISnbWr5uUygbh04WLCowqlyNAfMxXgOQyNVNFTMgZUyB-w_FuqLabbwNNJn0Z2qbqc-xYmpEy8ivpqfnoUhZ98YqREqvzr-D53QREL3crnJoInsuucZADKcj0c_8dVRnMsXfHPSe0RIjzkHvOQrPKZV5mu_ucMyjpKoC-8uqU84XL7IXo-xAJPEHk00FolLfda0X4yhklxcEpxgcZKtBkRBb0syGsBy0D1XKPjepsWyowEA0cH3bmp9_ARjxuOhHoWpPS8iVJ5kg8NySRqq50QxzDwf22WIEAO8G2MPlL8rWSwcUnCPs7oUY3Kug4heQ4dyIvG4AtEP4276TWlF3vHvkbrbZ_8dDo4e4Tiq8nvqwfKKL73F4LIs6iK39y8KurRIiN5mVVBedZrFu61L5LIw5ylDjr_3LOxBQmL-vxnTWlW0r-rkfvZxetO3M3SlALKx_3jOnZDA_MgtfpCA-61NxWG-TQRtM87YoDgdhGA1juS-AB3"},
headers=HEADERS,
timeout=60,
)
res.raise_for_status()
data = res.json()
for item in data["comments"]:
print(item.get("text"), item.get("reply_count"))
print("credits charged:", res.headers["x-credits-charged"])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. The recorded page had 4 items in comments. Live calls return current data in the same shape.
{
"comments": [
{
"id": "Y29tbWVudDoxMDExODE1NTQ0NDg1NDc3MV8xNjYyMjQ3MjgyMDI0MDM2",
"legacy_fbid": "1662247282024036",
"text": "Hassan Hafez wtf bro?",
"created_time": 1793583607,
"depth": 1,
"author": {
"id": "100015377746129",
"name": "Dennis Tomas",
"url": "https://www.facebook.com/people/Dennis-Tomas/100015377746129/"
},
"reaction_count": null,
"reply_count": 2,
"feedback_id": "ZmVlZGJhY2s6cGZiaWQwOVdqUWpIN1pCOXJ5MnFqRnd4WlRvOEFUakRuUlhiUDZKb0ZKcHZ1dXZVWkZnaUhFTGZzb0tqc2lTVjZQTlNzVmdReEhyNFdiUmR4…",
"expansion_token": "MjoxNzk1NTg5NjQ0OgF_iqhqNlYDsTY7uENjcX_pmebF-oPOPZ7X2TW4goZ7H3jlEyqXXwsRx4r3fet7p13h3AKINcl-B1ExFQofpmXqLSKYfqINat6PcZlN…",
"attachments": []
},
{
"id": "Y29tbWVudDoxMDExODE1NTQ0NDg1NDc3MV8yNjA4NjI3MDIyOTM1Mzk4",
"legacy_fbid": "2608627022935398",
"text": "Hassan Hafez very honest query, thanks",
"created_time": 1793597014,
"depth": 1,
"author": {
"id": "100003202533738",
"name": "O'raney Xtra Tembo",
"url": "https://www.facebook.com/oraney.tembo"
},
"reaction_count": null,
"reply_count": 1,
"feedback_id": "ZmVlZGJhY2s6cGZiaWQwNnE1dER5VmtiTDJXTmdzeFlmTWhzN1ZFSFRRQ2RWRTdSVmRxVUU1cW5rMXFEUk0zVjFxN2M5SnZKQVlwTDNZelBpYjdFd1VaNEFN…",
"expansion_token": "MjoxNzk1NTg5NjQ0OgF_J_xb7SkpI6B0KgtIK-nZsQQrKN9FRE-D8cJCnpBHmxnPvUBlneahS5e50n4DMQxd8hef0Yz1p1KBu9Dord0C3aNNZPy4dLU0eLPk…",
"attachments": []
},
"… 2 more"
],
"page_info": {
"has_next_page": true,
"end_cursor": "MToxNzk1NTg5NjQ0OgF_PENbDuM6OQ9xtGIVszsCHhkXOSo_LhQYzys_1MPW3uYhyTXdqRnAZ3IjHTiJFKTLUEm4gc7YURQGowFT2lia3abJvrkVfcj-SNz3…"
}
}Top-level fields
| Field | Type | Description |
|---|---|---|
comments | FacebookComment[] | – |
page_info | object | – |
Parameters
| Name | In | Type | Description |
|---|---|---|---|
feedback_id (required) | query | string | The comment’s feedback_id (not its id). |
expansion_token (required) | query | string | The comment’s expansion_token. |
after | query | string | The previous page’s end_cursor. |
Pagination
Pass after for the next page: The previous page’s end_cursor. Every page is a separate call at 2 credits per call.
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.
import os, time
import requests
def call(url, **kwargs):
headers = {"Authorization": f"Bearer {os.environ['GROUNDSOCIAL_API_KEY']}"}
for attempt in range(3):
res = requests.get(url, headers=headers, timeout=60, **kwargs)
if res.ok:
return res.json()
err = res.json()["error"]
# Branch on the stable code; the hint says what to do next.
if err["retryable"] and attempt < 2:
time.sleep(int(res.headers.get("Retry-After", 2)))
continue
raise RuntimeError(f"{err['code']}: {err.get('hint', err['message'])}")
data = call("https://api.groundsocial.dev/v1/facebook/comments/replies", params={"feedback_id": "ZmVlZGJhY2s6cGZiaWQwRlZTRW0yQlNpUFl3VmhDbTZheUJiSGcza2I3N2lYMUg2ZExhYTFKTXk4N3J1TUJKa2c0Z1o4dkNIWjl6bVJ3ZURycmtvRE5yOWZMWmpFQThudDlrSFR2QWI3UEd1a3VaNWlmMWw=", "expansion_token": "MjoxNzk1NTkyMjgxOgF_P6SokemgwnbmUm5tQd9IrppVFms8FLfDsfypSPQAraQFTmutXExMPBwM2bAJqkdJGGFkJ1sXM1E2Yog1SoEcGwT04mrhQrb_pUnkLq-ZnquWHXTCWcMAcuMoANUBH8V3MFISnbWr5uUygbh04WLCowqlyNAfMxXgOQyNVNFTMgZUyB-w_FuqLabbwNNJn0Z2qbqc-xYmpEy8ivpqfnoUhZ98YqREqvzr-D53QREL3crnJoInsuucZADKcj0c_8dVRnMsXfHPSe0RIjzkHvOQrPKZV5mu_ucMyjpKoC-8uqU84XL7IXo-xAJPEHk00FolLfda0X4yhklxcEpxgcZKtBkRBb0syGsBy0D1XKPjepsWyowEA0cH3bmp9_ARjxuOhHoWpPS8iVJ5kg8NySRqq50QxzDwf22WIEAO8G2MPlL8rWSwcUnCPs7oUY3Kug4heQ4dyIvG4AtEP4276TWlF3vHvkbrbZ_8dDo4e4Tiq8nvqwfKKL73F4LIs6iK39y8KurRIiN5mVVBedZrFu61L5LIw5ylDjr_3LOxBQmL-vxnTWlW0r-rkfvZxetO3M3SlALKx_3jOnZDA_MgtfpCA-61NxWG-TQRtM87YoDgdhGA1juS-AB3"})| Status | Meaning |
|---|---|
200 | A page of replies. |
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_comment_replies 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 (“Replies to a Facebook comment, paginated”), or call the tool directly:
{
"jsonrpc": "2.0",
"id": 1,
"method": "tools/call",
"params": {
"name": "facebook_comment_replies",
"arguments": {
"feedback_id": "ZmVlZGJhY2s6cGZiaWQwRlZTRW0yQlNpUFl3VmhDbTZheUJiSGcza2I3N2lYMUg2ZExhYTFKTXk4N3J1TUJKa2c0Z1o4dkNIWjl6bVJ3ZURycmtvRE5yOWZMWmpFQThudDlrSFR2QWI3UEd1a3VaNWlmMWw=",
"expansion_token": "MjoxNzk1NTkyMjgxOgF_P6SokemgwnbmUm5tQd9IrppVFms8FLfDsfypSPQAraQFTmutXExMPBwM2bAJqkdJGGFkJ1sXM1E2Yog1SoEcGwT04mrhQrb_pUnkLq-ZnquWHXTCWcMAcuMoANUBH8V3MFISnbWr5uUygbh04WLCowqlyNAfMxXgOQyNVNFTMgZUyB-w_FuqLabbwNNJn0Z2qbqc-xYmpEy8ivpqfnoUhZ98YqREqvzr-D53QREL3crnJoInsuucZADKcj0c_8dVRnMsXfHPSe0RIjzkHvOQrPKZV5mu_ucMyjpKoC-8uqU84XL7IXo-xAJPEHk00FolLfda0X4yhklxcEpxgcZKtBkRBb0syGsBy0D1XKPjepsWyowEA0cH3bmp9_ARjxuOhHoWpPS8iVJ5kg8NySRqq50QxzDwf22WIEAO8G2MPlL8rWSwcUnCPs7oUY3Kug4heQ4dyIvG4AtEP4276TWlF3vHvkbrbZ_8dDo4e4Tiq8nvqwfKKL73F4LIs6iK39y8KurRIiN5mVVBedZrFu61L5LIw5ylDjr_3LOxBQmL-vxnTWlW0r-rkfvZxetO3M3SlALKx_3jOnZDA_MgtfpCA-61NxWG-TQRtM87YoDgdhGA1juS-AB3"
}
}
}MCP setup for Claude Desktop, Cursor, VS Code and ChatGPT.
Expand a thread
Take feedback_id and expansion_token from a comment with reply_count above 0.
Keep going
- This call in JavaScript, TypeScript, Go, PHP, cURL.
- Facebook comment replies API reference: every field and status code.
- Facebook tutorials and all Python tutorials.
- Facebook API: every endpoint and price.
- How to scrape Facebook Ad Library search with Python: 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 Python: 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 Python: Find advertisers (Facebook Pages) in the Meta Ad Library by name.
- How to scrape Facebook Ad Library advertiser profile with Python: An advertiser’s Meta Ad Library profile: Page and Instagram details, political spend, top ad.
- How to scrape Facebook Ad Library ad details with Python: One Meta Ad Library ad with its details panel (EU reach by age and gender, payer, beneficiary).
- How to scrape Facebook Marketplace location search with Python: Find Facebook Marketplace places (cities, neighbourhoods, postcodes) with coordinates.
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.