# Facebook Posts Scraper (`khadinakbar/facebook-posts-scraper`) Actor

Scrape public Facebook page, profile, group, and post URLs into structured post records with text, media, links, and engagement counts. HTTP-first with optional provider fallback. MCP-ready.

- **URL**: https://apify.com/khadinakbar/facebook-posts-scraper.md
- **Developed by:** [Khadin Akbar](https://apify.com/khadinakbar) (community)
- **Categories:** Social media, Lead generation, MCP servers
- **Stats:** 23 total users, 6 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $3.50 / 1,000 post scrapeds

This Actor is paid per event and usage. You are charged both the fixed price for specific events and for Apify platform usage.

Learn more: https://docs.apify.com/actors/running/actors-in-store.md#pay-per-event

## What's an Apify Actor?

Actors are web data automations that power AI and operations. They run on the Apify platform to scrape websites, process data, connect APIs, and automate workflows.
In Batch mode, an Actor accepts a well-defined JSON input, performs an action which can take anything from a few seconds to a few hours,
and optionally produces a well-defined JSON output, datasets with results, or files in key-value store.
In Standby mode, an Actor provides a web server which can be used as a website, API, or an MCP server.
Actors are written with capital "A".

## How to integrate an Actor?

If asked about integration, you help developers integrate Actors into their projects.
You adapt to their stack and deliver integrations that are safe, well-documented, and production-ready.
The best way to integrate Actors is as follows.

- **AI agents and MCP clients** — the [Apify MCP server](https://docs.apify.com/integrations/mcp.md) at `https://mcp.apify.com` (remote, streamable HTTP, OAuth on first use).
- **Agentic workflows and local Actor development** — [Agent Skills](https://apify.com/.well-known/agent-skills/index.json) with the [Apify CLI](https://docs.apify.com/cli/docs.md): `npm install -g apify-cli`, then `apify login`.
- **JavaScript/TypeScript projects** — the official [JS/TS client](https://docs.apify.com/api/client/js/docs.md): `npm install apify-client`.
- **Python projects** — the official [Python client](https://docs.apify.com/api/client/python/docs.md): `pip install apify-client`.
- **Any other language** — the [REST API](https://docs.apify.com/api/v2.md).

For usage examples, see the [API](#api) section below.

For more details, see Apify documentation as [Markdown index](https://docs.apify.com/llms.txt) and [Markdown full-text](https://docs.apify.com/llms-full.txt).

# README

## Facebook Posts Scraper

Scrape public Facebook posts from page, profile, group, and direct post URLs. The actor returns clean JSON records with post URL, author, text, timestamp, engagement counts, media URLs, outbound links, source URL, and scrape metadata.

This actor is built for social listening, competitive research, brand monitoring, and AI-agent workflows that need structured public Facebook post data without handling browser sessions or cookies.

### What it extracts

Each dataset item can include:

- `postUrl` and `postId`
- `authorName` and `authorUrl`
- `text`
- `timestamp` and `timestampText`
- `reactionsCount`, `commentsCount`, and `sharesCount`
- `media`
- `externalLinks`
- `sourceUrl`
- `scrapeSource`
- `scrapedAt`

The scraper is HTTP-first and uses mobile/basic Facebook pages where available. That keeps runs fast and cheaper than a browser-heavy workflow. Facebook can still hide, delete, age-gate, or login-gate content; those sources are reported in the `OUTPUT` summary instead of hard-failing the run.

### Input

```json
{
  "startUrls": [
    { "url": "https://www.facebook.com/NASA" },
    { "url": "https://www.facebook.com/NASA/posts/10159744600446772" }
  ],
  "resultsLimit": 50,
  "maxPostsPerSource": 25,
  "scrapeDetails": true,
  "fallbackProvider": "auto",
  "onlyPostsNewerThan": "2026-01-01",
  "proxyConfiguration": {
    "useApifyProxy": true,
    "apifyProxyGroups": ["RESIDENTIAL"]
  }
}
```

### Output example

```json
{
  "sourceUrl": "https://www.facebook.com/NASA",
  "postUrl": "https://www.facebook.com/NASA/posts/123456789",
  "postId": "123456789",
  "authorName": "NASA",
  "authorUrl": "https://www.facebook.com/NASA",
  "text": "A new image from space...",
  "timestamp": "2026-06-01T00:00:00.000Z",
  "timestampText": "June 1, 2026",
  "reactionsCount": 1200,
  "commentsCount": 34,
  "sharesCount": 5,
  "media": ["https://scontent.xx.fbcdn.net/image.jpg"],
  "externalLinks": ["https://www.nasa.gov/"],
  "scrapeSource": "post-detail",
  "scrapedAt": "2026-06-08T12:00:00.000Z"
}
```

### Notes

- Public data only. Private groups, private profiles, deleted posts, login-only posts, and age-gated pages may not return results.
- Residential proxies are enabled by default because Facebook often blocks datacenter IPs.
- Provider fallback is optional. Set `SCRAPECREATORS_API_KEY`, `SOCIAVAULT_API_KEY`, or `SOCIALVAULT_API_KEY` in the actor environment and keep `fallbackProvider` as `auto` to use public-data APIs after Facebook blocks or returns empty HTML.
- Date filters are best-effort. If Facebook exposes unparseable relative text, the actor keeps the post rather than silently dropping data.
- `includeRawHtml` is for debugging only and increases dataset size.

### Pricing

Pay-per-event configuration:

- `apify-actor-start`: `$0.00005`
- `post-scraped`: `$0.0035` per dataset item

`resultsLimit` is the primary user-facing cost cap.

### Local development

```bash
npm install
npm test
apify run --input='{"startUrls":[{"url":"https://www.facebook.com/NASA"}],"resultsLimit":5}'
```

# Actor input Schema

## `startUrls` (type: `array`):

One or more public Facebook page, profile, group, or post URLs. The actor converts supported URLs to mobile/basic Facebook for fast public extraction. Private, deleted, age-gated, or login-only content may return no posts.

## `resultsLimit` (type: `integer`):

Maximum number of post records to emit across all sources. Use this as your primary cost cap; each emitted post charges the post-scraped event.

## `maxPostsPerSource` (type: `integer`):

Maximum number of posts to collect from each page, profile, or group URL before moving to the next source. Direct post URLs count as one source.

## `scrapeDetails` (type: `boolean`):

When enabled, the actor opens each discovered post URL to enrich text, media, outbound links, and engagement counts. Disable for faster, cheaper timeline-preview extraction.

## `fallbackProvider` (type: `string`):

Optional fallback after Facebook blocks or returns empty public HTML. auto uses SCRAPECREATORS\_API\_KEY first and SOCIAVAULT\_API\_KEY second when those environment variables are configured. none disables provider calls.

## `onlyPostsNewerThan` (type: `string`):

Optional date filter. Accepts ISO dates such as 2026-01-01 or natural JavaScript date strings. Posts with unparseable Facebook timestamp text are kept rather than silently dropped.

## `onlyPostsOlderThan` (type: `string`):

Optional upper date filter. Accepts ISO dates such as 2026-06-01 or natural JavaScript date strings. Posts with unparseable Facebook timestamp text are kept rather than silently dropped.

## `includeRawHtml` (type: `boolean`):

Debug option. Adds a truncated rawHtml field to detail records. Leave disabled for normal runs because raw HTML increases dataset size.

## `proxyConfiguration` (type: `object`):

Proxy settings for requests. Residential Apify Proxy is the default because Facebook often blocks datacenter IPs and local network ranges.

## Actor input object example

```json
{
  "startUrls": [
    {
      "url": "https://www.facebook.com/NASA"
    },
    {
      "url": "https://www.facebook.com/NASA/posts/10159744600446772"
    }
  ],
  "resultsLimit": 100,
  "maxPostsPerSource": 50,
  "scrapeDetails": true,
  "fallbackProvider": "auto",
  "onlyPostsNewerThan": "2026-01-01",
  "onlyPostsOlderThan": "2026-06-01",
  "includeRawHtml": false,
  "proxyConfiguration": {
    "useApifyProxy": true,
    "apifyProxyGroups": [
      "RESIDENTIAL"
    ]
  }
}
```

# Actor output Schema

## `dataset` (type: `string`):

No description

## `summary` (type: `string`):

No description

## `runSummary` (type: `string`):

No description

# API

You can run this Actor programmatically using our API. Below are code examples in JavaScript, Python, and CLI, as well as the OpenAPI specification and MCP server setup.

## JavaScript example

```javascript
import { ApifyClient } from 'apify-client';

// Initialize the ApifyClient with your Apify API token
// Replace the '<YOUR_API_TOKEN>' with your token
const client = new ApifyClient({
    token: '<YOUR_API_TOKEN>',
});

// Prepare Actor input
const input = {
    "startUrls": [
        {
            "url": "https://www.facebook.com/NASA"
        }
    ]
};

// Run the Actor and wait for it to finish
const run = await client.actor("khadinakbar/facebook-posts-scraper").call(input);

// Fetch and print Actor results from the run's dataset (if any)
console.log('Results from dataset');
console.log(`💾 Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);
const { items } = await client.dataset(run.defaultDatasetId).listItems();
items.forEach((item) => {
    console.dir(item);
});

// 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/js/docs

```

## Python example

```python
from apify_client import ApifyClient

# Initialize the ApifyClient with your Apify API token
# Replace '<YOUR_API_TOKEN>' with your token.
client = ApifyClient("<YOUR_API_TOKEN>")

# Prepare the Actor input
run_input = { "startUrls": [{ "url": "https://www.facebook.com/NASA" }] }

# Run the Actor and wait for it to finish
run = client.actor("khadinakbar/facebook-posts-scraper").call(run_input=run_input)

# Fetch and print Actor results from the run's dataset (if there are any)
print(f"💾 Check your data here: https://console.apify.com/storage/datasets/{run.default_dataset_id}")
for item in client.dataset(run.default_dataset_id).iterate_items():
    print(item)

# 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/python/docs/quick-start

```

## CLI example

```bash
echo '{
  "startUrls": [
    {
      "url": "https://www.facebook.com/NASA"
    }
  ]
}' |
apify call khadinakbar/facebook-posts-scraper --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,khadinakbar/facebook-posts-scraper"
        }
    }
}

```

The hosted server signs you in with OAuth on first connect, so no API token belongs in this config. Clients without OAuth support can send an `Authorization: Bearer <APIFY_API_TOKEN>` header instead, using a token from API & Integrations in Apify Console (https://console.apify.com/settings/integrations).

## OpenAPI specification

Download the OpenAPI definition: https://api.apify.com/v2/actors/dD4BPO6E4EnLfRj6z/builds/fBpBDwhOZ2RSGfPKY/openapi.json
