# Facebook data in Python. Pay per record.

> Get Facebook data into Python: one HTTPS call per operation, a free quote first, pay per record from $0.0022 per record.

Canonical: https://apiforagents.dev/integrations/python/facebook · Updated 2026-10-21

Call the Facebook API from Python with one HTTPS request per operation: pages, posts by a person, reels and comments. Every call can be quoted free first, and you pay per record that comes back, from $0.0022 per record, from a prepaid balance with $0.10 free to start.

- Works with: Python
- Operations: 9
- Price: From $0.0022 per record
- Free to start: $0.10

## Set it up in Python

1. pip install requests, and put your API key in the AFA_KEY environment variable.
2. Call the function below once per operation; quote first with estimate_only=True.

## Pages

python · Facebook pages:

```python
import os, requests

def facebook(op: str, params: dict, estimate_only: bool = False) -> dict:
    r = requests.post(
        "https://apiforagents.dev/v1/facebook",
        headers={"Authorization": f"Bearer {os.environ['AFA_KEY']}"},
        json={"op": op, **params, "estimateOnly": estimate_only},
        timeout=120,
    )
    body = r.json()
    if r.status_code != 200:
        raise RuntimeError(f"{body.get('error')}: {body.get('error_description')}")
    return body  # read body["coverage"] before body["data"]

quote = facebook("pages", {
    "subjects": ["nike","natgeo"],
}, estimate_only=True)
print(quote["cost"]["wouldChargeUsd"])
```

## Posts by a person

python · Facebook posts:

```python
import os, requests

def facebook(op: str, params: dict, estimate_only: bool = False) -> dict:
    r = requests.post(
        "https://apiforagents.dev/v1/facebook",
        headers={"Authorization": f"Bearer {os.environ['AFA_KEY']}"},
        json={"op": op, **params, "estimateOnly": estimate_only},
        timeout=120,
    )
    body = r.json()
    if r.status_code != 200:
        raise RuntimeError(f"{body.get('error')}: {body.get('error_description')}")
    return body  # read body["coverage"] before body["data"]

quote = facebook("posts", {
    "subject": "nike",
    "since": "2026-10-01",
    "limit": 20,
}, estimate_only=True)
print(quote["cost"]["wouldChargeUsd"])
```

## Reels

python · Facebook reels:

```python
import os, requests

def facebook(op: str, params: dict, estimate_only: bool = False) -> dict:
    r = requests.post(
        "https://apiforagents.dev/v1/facebook",
        headers={"Authorization": f"Bearer {os.environ['AFA_KEY']}"},
        json={"op": op, **params, "estimateOnly": estimate_only},
        timeout=120,
    )
    body = r.json()
    if r.status_code != 200:
        raise RuntimeError(f"{body.get('error')}: {body.get('error_description')}")
    return body  # read body["coverage"] before body["data"]

quote = facebook("reels", {
    "subject": "natgeo",
    "limit": 10,
}, estimate_only=True)
print(quote["cost"]["wouldChargeUsd"])
```

## Comments

python · Facebook comments:

```python
import os, requests

def facebook(op: str, params: dict, estimate_only: bool = False) -> dict:
    r = requests.post(
        "https://apiforagents.dev/v1/facebook",
        headers={"Authorization": f"Bearer {os.environ['AFA_KEY']}"},
        json={"op": op, **params, "estimateOnly": estimate_only},
        timeout=120,
    )
    body = r.json()
    if r.status_code != 200:
        raise RuntimeError(f"{body.get('error')}: {body.get('error_description')}")
    return body  # read body["coverage"] before body["data"]

quote = facebook("comments", {
    "subjects": ["https://www.facebook.com/nike/posts/<post-id>"],
    "sort": "top",
    "limit": 50,
}, estimate_only=True)
print(quote["cost"]["wouldChargeUsd"])
```

## Facebook operations you can call

List prices per record. A call can carry a minimum, so quote first: the quote is free and is the most a call can cost.

| Operation | Price per record |
|---|---|
| Pages | $0.009 |
| Posts by a person | $0.0045 |
| Reels | $0.0045 |
| Comments | $0.0022 |
| Reviews | $0.0022 |
| Followers | $0.0067 |
| Ads | $0.0045 |
| Events | $0.009 |
| Marketplace | $0.009 |

## Each operation in detail

- [Facebook Page API](https://apiforagents.dev/platforms/facebook/page-api): inputs, fields, sample, price
- [Facebook Posts API](https://apiforagents.dev/platforms/facebook/posts-api): inputs, fields, sample, price
- [Facebook Reels API](https://apiforagents.dev/platforms/facebook/reels-api): inputs, fields, sample, price
- [Facebook Comments API](https://apiforagents.dev/platforms/facebook/comments-api): inputs, fields, sample, price
- [Facebook Reviews API](https://apiforagents.dev/platforms/facebook/reviews-api): inputs, fields, sample, price
- [Facebook Followers API](https://apiforagents.dev/platforms/facebook/followers-api): inputs, fields, sample, price
- [Facebook Ad Library API](https://apiforagents.dev/platforms/facebook/ad-library-api): inputs, fields, sample, price
- [Facebook Events API](https://apiforagents.dev/platforms/facebook/events-api): inputs, fields, sample, price
- [Facebook Marketplace API](https://apiforagents.dev/platforms/facebook/marketplace-api): inputs, fields, sample, price

## Questions

### Is there an SDK?

No SDK is needed: it is one HTTPS POST per call to https://apiforagents.dev/v1/facebook, so requests or httpx is enough.

### How do I handle errors?

A refusal answers with an error code and a plain description; a subject that did not come back is listed in coverage with the reason, and is not charged.

### What does Facebook data cost?

Pay as you go, from $0.0022 per record at the list price. Some calls carry a minimum, so quote first with "estimateOnly": true: it is free and is the most the call can cost. Records that do not come back are refunded.

## Why API for Agents

- One key for 26 platforms: social, commerce, jobs, places, search and contacts, with one request shape and one response shape.
- A free quote before any spend: add "estimateOnly": true to any call and see the most it can cost.
- Pay per record in US dollars. No subscription, nothing expires, top-ups from $5.
- $0.10 free to try, no card. An AI agent can sign itself up in one request; a person claims it later.
- Measured, not estimated: every answer says when each row was measured, whether it was fresh or a recent capture, and how sure to be of each field.
- Partial success is success: anything that could not be fetched is named with a reason, and the charge settles to what came back, never above the quote.
- Typed fields that keep their names whichever source answered, and a details object last with everything else the source sent, under our own field names.
- Try any endpoint in the playground and download the answer as CSV or JSON.

## Start

The playground runs any endpoint by hand: pick a platform and what you want from it, fill a short form named in plain words (or press Use sample input), see the free quote on the Run button, run it, then read the answer as a table or JSON and download it as CSV or JSON. The same call is written out as cURL, Python and Node while you type. Open it at https://apiforagents.dev/dashboard/run?platform=facebook (sign in first).

Agents register at https://apiforagents.dev/auth.md (one POST, $0.10 free). People: https://apiforagents.dev/docs#start. Prices: https://apiforagents.dev/pricing.md
