100 free credits. No credit card required. Get a key

How to scrape Facebook comment replies with Python

The replies to one Facebook comment, page by page, from the comment’s feedback_id and expansion_token.

The examples use requests with a timeout and raise_for_status(), and read the JSON as plain dicts.

GET /v1/facebook/comments/replies2 credits per callRefunded on failureBeta

Before you start

  1. Get an API keySign up for 100 free credits, no card. Keys start with gs_live_.
  2. Put it in the environmentEvery example reads it from GROUNDSOCIAL_API_KEY: export GROUNDSOCIAL_API_KEY=gs_live_…
  3. Set up Pythonpip 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.

main.py
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.

200 OK
{
  "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

FieldTypeDescription
commentsFacebookComment[]–
page_infoobject–

Parameters

NameInTypeDescription
feedback_id (required)querystringThe comment’s feedback_id (not its id).
expansion_token (required)querystringThe comment’s expansion_token.
afterquerystringThe 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.

Errors
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"})
StatusMeaning
200A page of replies.
400Invalid input. Nothing was charged.
401Missing or invalid API key.
402Not enough credits, a spend cap was reached, or payment is required.
403The target is private, or the account is suspended.
404The ad, Page or advertiser is not in the Meta Ad Library.
429Too many requests. Wait for Retry-After seconds.
503Facebook is temporarily unavailable. Retryable; nothing was charged.

Every error code and what to do about it.

Pricing

Cost
Per call2 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 callRefunded, 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:

bash
claude mcp add --transport http groundsocial https://api.groundsocial.dev/mcp

Then ask for it in words (“Replies to a Facebook comment, paginated”), or call the tool directly:

json
{
  "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

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.