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 post comments API from Python
GET /v1/facebook/posts/comments. 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/posts/comments",
params={"url": "https://www.facebook.com/zuck/posts/pfbid0Cj47VyownRywjfYupyWgyDKSmv3bFUDRWLpwjDzPZdF2mFfRMTWkyMS3vVRo5reyl", "sort": "all"},
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": "Y29tbWVudDoxMDExODE1NTQ0NDg1NDc3MV8xMTk4OTc5MTI5NTMwNzE0",
"legacy_fbid": "1198979129530714",
"text": "What does a human burger taste like? 😉",
"created_time": 1793558085,
"depth": 0,
"author": {
"id": "pfbid021StH2n3mR7TLVbLXnWPjqVdsugKkZsoiqacTjoP7PmA5oafkXG2BPXBHyTgfGsZsl",
"name": "Hassan Hafez",
"url": null
},
"reaction_count": null,
"reply_count": 17,
"feedback_id": "ZmVlZGJhY2s6cGZiaWQwRlZTRW0yQlNpUFl3VmhDbTZheUJiSGcza2I3N2lYMUg2ZExhYTFKTXk4N3J1TUJKa2c0Z1o4dkNIWjl6bVJ3ZURycmtvRE5yOWZM…",
"expansion_token": "MjoxNzk1NTg5NjQxOgF_h9VsScLekpjk1J6EP5Sf8feunLqTyazmQTijGYe_Kstl6iT2AmMEBzitxgcfLx3Dv4pJ4mQ-SZ2hiMAzclqepHDlwfCSVd_jbcvr…",
"attachments": []
},
{
"id": "Y29tbWVudDoxMDExODE1NTQ0NDg1NDc3MV8xMDU4MTYwMTkwNTk0NTEy",
"legacy_fbid": "1058160190594512",
"text": "You all could have done the characters from Burger Time 😄",
"created_time": 1793560720,
"depth": 0,
"author": {
"id": "pfbid02iz4RhdW3FTRS4LgtRhPWYWpXqYx1dEuVKVc7AvVMtxSMyrDhgoNfbig8UqMLU4J8l",
"name": "Teri Mut",
"url": null
},
"reaction_count": null,
"reply_count": 5,
"feedback_id": "ZmVlZGJhY2s6cGZiaWQwMmRQa1BzRmljVXZDY1pDUkRCUGdtU1RTMkxUbjVmWTZVd01LMlFjV1M3aGtqNlNqOU55MjZveG9NUkpQcGJtSHBMQnFVOUR6RFZL…",
"expansion_token": "MjoxNzk1NTg5NjQxOgF_ZLJQ7ddN8DnhdsUI4HBjHeNSyGiAtjPzCXTB1EA6WVGfljk48w0MvipVOsP8MAXN2nkYnzj2nUKzLFmYKAmEOo8sFjuC6Nm1uIme…",
"attachments": []
},
"… 2 more"
],
"page_info": {
"has_next_page": true,
"end_cursor": "MToxNzk1NTg5NjQxOgF_NEMFwzJPXp1_R2IeYFcPbRu9dAljSRcO1dm6LYpwdrcvjyO3TAYljTx2WQDkrWz3RAlBys7Kqbrf5wUtyKwpVY1Jri22lmDUbVxw…"
}
}Top-level fields
| Field | Type | Description |
|---|---|---|
comments | FacebookComment[] | – |
page_info | object | – |
Parameters
| Name | In | Type | Description |
|---|---|---|---|
url | query | string | The post URL. |
feedback_id | query | string | The post’s feedback_id. |
sort | query | "most_relevant" | "all" | One of most_relevant, all. |
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/posts/comments", params={"url": "https://www.facebook.com/zuck/posts/pfbid0Cj47VyownRywjfYupyWgyDKSmv3bFUDRWLpwjDzPZdF2mFfRMTWkyMS3vVRo5reyl", "sort": "all"})| Status | Meaning |
|---|---|
200 | A page of comments. |
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_comments 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 Facebook post’s comments, paginated, ranked or all”), or call the tool directly:
{
"jsonrpc": "2.0",
"id": 1,
"method": "tools/call",
"params": {
"name": "facebook_post_comments",
"arguments": {
"url": "https://www.facebook.com/zuck/posts/pfbid0Cj47VyownRywjfYupyWgyDKSmv3bFUDRWLpwjDzPZdF2mFfRMTWkyMS3vVRo5reyl",
"sort": "all"
}
}
}MCP setup for Claude Desktop, Cursor, VS Code and ChatGPT.
Read what people say
Page with after until has_next_page is false; pass a comment’s feedback_id and expansion_token to the replies endpoint for its thread.
Keep going
- This call in JavaScript, TypeScript, Go, PHP, cURL.
- Facebook post comments 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.