# Facebook Engagement Scraper (`andy-ng/facebook-engagement-scraper`) Actor

- **URL**: https://apify.com/andy-ng/facebook-engagement-scraper.md
- **Developed by:** [Andy Nguyen](https://apify.com/andy-ng) (community)
- **Categories:**
- **Stats:** 4 total users, 3 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $2.00 / 1,000 results

This Actor is paid per event. You are not charged for the Apify platform usage, but only a fixed price for specific events.

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 Post Engagement Scraper

An Apify Actor that extracts normalized engagement snapshots from direct public Facebook post URLs. It follows an HTTP-first strategy and retries incomplete or JavaScript-rendered pages with a controlled Playwright browser.

The Actor is intentionally scoped to direct posts. Page timelines, profile crawling, keyword search, private content, and comment pagination are outside the MVP.

### Supported URLs

- `/{page}/posts/{id}` and `/{page}/posts/pfbid...`
- `/groups/{group}/posts/{id}` for publicly visible group posts
- `/reel/{id}`, `/videos/{id}`, and `/watch/?v={id}`
- `/photo.php?fbid={id}`
- `story.php` and `permalink.php` legacy URLs
- `/share/p/...`, `/share/v/...`, `/share/r/...`, and `fb.watch` redirects

Page roots such as `https://facebook.com/NASA` are rejected because this Actor does not crawl timelines.

### Input

```json
{
  "startUrls": [
    { "url": "https://www.facebook.com/NASA/posts/123456789" }
  ],
  "includeReactionBreakdown": true,
  "maxConcurrency": 5,
  "proxyConfiguration": { "useApifyProxy": true }
}
```

The Actor accepts up to 1,000 URLs. Tracking parameters are removed before run-wide deduplication. Facebook identity parameters such as `story_fbid`, `fbid`, `id`, and `v` are retained.

### Output

Each unique submitted URL produces at most one dataset row. A failed URL does not terminate the rest of the batch.

```json
{
  "postId": "123456789",
  "code": "pfbidExample",
  "url": "https://www.facebook.com/NASA/posts/pfbidExample",
  "originalUrl": "https://m.facebook.com/share/p/example/",
  "postType": "video",
  "text": "A new view of the cosmos #NASA",
  "sharedUrl": "https://example.com/article",
  "createdAt": "2026-09-05T12:34:56.000Z",
  "reactionCount": 1200,
  "reactionBreakdown": {
    "like": 900,
    "love": 200,
    "wow": 100
  },
  "commentCount": 80,
  "shareCount": 20,
  "viewCount": 15000,
  "engagementCount": 1300,
  "author": {
    "id": "42",
    "username": "NASA",
    "name": "NASA",
    "isVerified": true,
    "profileUrl": "https://www.facebook.com/NASA",
    "profilePicUrl": "https://scontent...jpg",
    "type": "page"
  },
  "media": [],
  "hashtags": ["NASA"],
  "mentions": [],
  "status": "success",
  "missingFields": [],
  "error": null,
  "scrapedAt": "2026-09-06T14:20:10.000Z"
}
```

Facebook does not expose equivalents for Threads `quoteCount` and `isReply`, so they are intentionally absent. Facebook fields use their native semantics:

- `reactionCount` instead of Threads `likeCount`
- `commentCount` instead of Threads `replyCount`
- `shareCount` instead of Threads `repostCount`
- `engagementCount = reactionCount + commentCount + shareCount`

`sharedUrl` is the external destination linked by the post. It is extracted from the post text, GraphQL attachment data, or the rendered link preview; Facebook link-shim URLs such as `l.facebook.com/l.php`, mobile variants, warning pages, and legacy redirects are unwrapped. It remains `null` when the post has no external destination.

Unavailable counts are `null`, never fabricated as zero. A row is `partial` when `postId` or a core engagement count is unavailable and `missingFields` lists those fields.

### Extraction strategy

1. Validate, normalize, and deduplicate input URLs.
2. Fetch public HTML with CheerioCrawler.
3. Parse embedded structured payloads, Open Graph metadata, and engagement objects.
4. Send incomplete pages to PlaywrightCrawler.
5. Merge browser and HTTP results without replacing known values with `null`.
6. Emit `success`, `partial`, `not_found`, `private`, `blocked`, or `failed` rows.

`sharedThumbnailUrl` preserves an explicit preview when available, then falls back to the first extracted media preview or image URL (including Open Graph media). Video stream URLs are never used as inferred thumbnails. Generic `Story`/`Post` types use media to distinguish photos and videos; explicit reel and link types are preserved.

Only public, logged-out Facebook content is in scope. Use this Actor in compliance with Facebook's terms and applicable privacy and data-protection laws.

### Development

```bash
npm install
npm run check
```

Local Actor input belongs in `storage/key_value_stores/default/INPUT.json`, then run:

```bash
npm run build
npm start
```

# Actor input Schema

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

Public Facebook post, photo, video, reel, watch, permalink, or share URLs.

## `includeReactionBreakdown` (type: `boolean`):

Extract Like, Love, Care, Haha, Wow, Sad, and Angry counts when Facebook exposes them.

## `maxConcurrency` (type: `integer`):

Maximum number of HTTP requests processed in parallel. Browser fallback uses a lower safe limit.

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

Proxy settings. Residential proxies are recommended for Facebook public pages.

## Actor input object example

```json
{
  "startUrls": [
    {
      "url": "https://www.facebook.com/NASA/posts/123456789"
    }
  ],
  "includeReactionBreakdown": true,
  "maxConcurrency": 5,
  "proxyConfiguration": {
    "useApifyProxy": true
  }
}
```

# Actor output Schema

## `results` (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/posts/123456789"
        }
    ]
};

// Run the Actor and wait for it to finish
const run = await client.actor("andy-ng/facebook-engagement-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/posts/123456789" }] }

# Run the Actor and wait for it to finish
run = client.actor("andy-ng/facebook-engagement-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/posts/123456789"
    }
  ]
}' |
apify call andy-ng/facebook-engagement-scraper --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,andy-ng/facebook-engagement-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/UeoE2idJGiOohHzBa/builds/4FedBcjU8PBQYSjFg/openapi.json
