# Facebook Posts Search API - Real-Time Keyword Search (`topapi/facebook-posts-search-api`) Actor

Search public Facebook posts by keyword in one HTTP request and get the posts back in the response: text, author, date, reactions, comments, shares, views, media, group and place. Top or recent, date and location filters, cursor paging. Works from code, n8n, Make and AI agents (MCP).

- **URL**: https://apify.com/topapi/facebook-posts-search-api.md
- **Developed by:** [Top Api](https://apify.com/topapi) (community)
- **Categories:** Social media, Marketing, Lead generation
- **Features:** Limited permissions, Multi-tenant, Server interface
- **Stats:** 1 total users, 0 monthly users, 0.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $2.40 / 1,000 post scrapeds

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?

An Actor is a serverless cloud program that runs on the Apify platform. It has two run modes.
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.

Apify vocabulary and the platform model are defined once, in the agent quickstart at https://apify.com/agents.md.

## 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.

Do not guess an integration path. Every one of them is in the agent quickstart at https://apify.com/agents.md: the Apify MCP server, Agent Skills with the Apify CLI, the JavaScript and Python clients, the REST API, and the account-free path for an agent with no human to sign in. It also carries the rule on stating cost before the first paid run.

For examples already wired to this Actor's own input schema, see the [API](#api) section below.

Each client library has reference documentation the quickstart does not restate: [JavaScript/TypeScript](https://docs.apify.com/api/client/js/docs.md) (`npm install apify-client`) and [Python](https://docs.apify.com/api/client/python/docs.md) (`pip install apify-client`).

# README

## 🔎 Facebook Posts Search API - Real-Time Keyword Search

**Facebook Posts Search API** searches public Facebook posts by keyword in **one HTTP request** and returns the posts in
the response: no run to start, no dataset to fetch. It is an Apify **Server Actor**, so it also works as a **tool for
AI agents (MCP)** and as one **HTTP Request** step in n8n, Make or Zapier.

Each post carries its text, author Page or profile, date, reactions by type, comments, shares, video views, photos,
video and link attachments, group and place. Search in Facebook's own relevance order or newest first, inside a date
window, near a place, and keep only the post types you want. **You pay per post returned**; a search that returns no
post costs nothing.

### ✨ What you get

- 📝 **Post text**, hashtags and mentions
- 👤 **Author**: name, id, profile or Page URL, type (user, Page, business Page)
- 📅 **Date**: Unix timestamp and ISO `published_at`
- ❤️ **Engagement**: reactions total and by type (like, love, care, haha, wow, sad, angry), comments, shares, video views
- 🖼️ **Media**: photos and albums, video URL / id / thumbnail / duration, link previews, shared posts
- 👥 **Group and place** when the post is in a group or tagged at a place
- 💬 **Top public comments and video files** with `includePostDetails`
- 🧭 **Filters**: top or recent, date window, place, post type, source (groups / Pages), minimum reactions, keywords
- 📄 **Paging**: `meta.nextCursor` reads the next posts of the same search
- 🔑 No Facebook account, no cookies, no API key of yours (only your Apify token)

### 🚀 How to call it

Every request needs your **Apify API token** in the `Authorization` header.

#### GET

```bash
curl "https://topapi--facebook-posts-search-api.apify.actor/search?query=coffee&maxPosts=10" \
  -H "Authorization: Bearer <YOUR_APIFY_TOKEN>"
```

#### POST

```bash
curl -X POST "https://topapi--facebook-posts-search-api.apify.actor/search" \
  -H "Authorization: Bearer <YOUR_APIFY_TOKEN>" -H "Content-Type: application/json" \
  -d '{"query": "solar panels", "sortBy": "recent", "startDate": "7 days", "maxPosts": 20}'
```

#### Python

```python
import requests

URL = "https://topapi--facebook-posts-search-api.apify.actor/search"
HEADERS = {"Authorization": "Bearer <YOUR_APIFY_TOKEN>"}
params = {"query": "electric cars", "maxPosts": 20, "sortBy": "recent"}
posts = []
for _ in range(3):                       # three pages of results
    r = requests.get(URL, params=params, headers=HEADERS, timeout=180)
    data = r.json()
    if r.status_code != 200:
        print(r.status_code, data["error"]["type"]); break
    posts += data["items"]
    if not data["meta"]["nextCursor"]:
        break
    params["cursor"] = data["meta"]["nextCursor"]
print(len(posts), "posts")
```

#### JavaScript

```javascript
const res = await fetch(
    'https://topapi--facebook-posts-search-api.apify.actor/search?query=coffee&maxPosts=10',
    { headers: { Authorization: `Bearer ${process.env.APIFY_TOKEN}` } },
);
const { items, meta } = await res.json();
console.log(items.length, meta.nextCursor);
```

#### n8n, Make, Zapier

One **HTTP Request** step: method `GET`, URL `https://topapi--facebook-posts-search-api.apify.actor/search`, query
parameters `query` and `maxPosts`, header `Authorization` = `Bearer <YOUR_APIFY_TOKEN>`. The posts are `items`.

#### AI agents (MCP)

MCP server URL: `https://topapi--facebook-posts-search-api.apify.actor/mcp` (Streamable HTTP, header
`Authorization: Bearer <YOUR_APIFY_TOKEN>`). Tool: `search_posts`, same parameters as the HTTP endpoint. Use
`compact: true` to give the model only the core fields.

### ⚙️ Parameters

| Parameter | Type | Default | What it does |
|---|---|---|---|
| `query` | string | required | What to search for, as typed into Facebook's search box, or a `facebook.com/search/...?q=` or `/hashtag/...` URL. Also accepted as `q`, `keyword`, `searchQuery`, `term`. |
| `maxPosts` | integer | `10` | Posts to return, 1-50. Facebook serves 5-6 posts a page. |
| `sortBy` | `top` | `recent` | `top` | Facebook's relevance order, or newest first. |
| `startDate` | string | | Only posts on or after this day: `2026-09-01`, `7 days`, `2 months`, or a day count. |
| `endDate` | string | | Only posts on or before this day (the whole day counts). |
| `locationUid` | string | | A numeric Facebook place id. |
| `mustContainQuery` | boolean | `false` | Only posts whose text contains the query (Facebook's search is fuzzy). |
| `keywordFilter` | string | | Comma-separated words: keep posts whose text, author, link, group or place mention any of them. |
| `postType` | `all` | `photo` | `video` | `link` | `text` | `all` | Only one kind of post. |
| `postSource` | `all` | `groups` | `pages_and_profiles` | `business_pages` | `all` | Only group posts, Page/profile posts, or business Page posts. |
| `minReactions` | integer | `0` | Only posts with at least this many reactions. |
| `includePostDetails` | boolean | `false` | Add the top public comments, video file URLs and view count. |
| `compact` | boolean | `false` | Core fields only, for AI agents. |
| `cursor` | string | | The previous response's `meta.nextCursor`, with the same query and filters, to read further. |

`GET /` lists the endpoints; the **Server** tab in Console shows the OpenAPI description.

### 📦 Response

A real post from a `coffee` search (2026-11-18), trimmed:

```json
{
  "ok": true,
  "count": 10,
  "items": [{
    "post_id": "1158323430087039",
    "type": "photo",
    "url": "https://www.facebook.com/permalink.php?story_fbid=pfbid02MHX4msx...&id=100077281797833",
    "message": "Have a nice day 🤎☕",
    "published_at": "2026-11-17T04:00:03.000Z",
    "author": { "id": "100077281797833", "name": "Coffee.", "url": "https://www.facebook.com/people/Coffee/100077281797833/", "type": "user" },
    "reactions_count": 583,
    "comments_count": 13,
    "reshare_count": 69,
    "reactions": { "like": 514, "love": 63, "care": 5, "wow": 1, "haha": 0, "sad": 0, "angry": 0 }
  }],
  "meta": { "query": "coffee", "sort": "top", "pages": 2, "read": 12, "filtered": {}, "stopReason": "max_posts", "nextCursor": "{\"page...", "charged": { "post-scraped": 10 }, "ms": 5272 }
}
```

| Field | Filled (46 posts from 11 search pages, 2026-11-18) |
|---|---|
| `post_id`, `type`, `url`, `timestamp`, `published_at`, `author.name`, `author.id`, `author.url` | 100% |
| `message`, `reactions_count`, `comments_count`, `reshare_count` | 100% |
| `image`, `reactions` (by type) | 93% |
| `hashtags` | 30% (posts that use them) |
| `group` | 22% (group posts) |
| `external_url`, `video`, `location`, `video_view_count` | 2-4% (link, video and place posts in this sample) |
| `top_comments`, `video_files` | with `includePostDetails` (2 of 2 in the test, 6-10 comments each) |

### 🧾 Status codes (and what is charged)

| HTTP | `error.type` | Meaning | Charged |
|---|---|---|---|
| `200` | | Posts returned | `post-scraped` per post, `post-details` per post with details |
| `400` | `invalid-input` | Bad parameter or date | No |
| `404` | `no-posts` | No public post for the query, or none passed your filters. `error.meta` shows what was read and filtered | No |
| `410` | `cursor-expired` | Facebook no longer accepts that cursor: search again without it | No |
| `429` | `too-many-requests` | More than 4 of your requests in flight at once | No |
| `503` | `blocked`, `timeout` | Facebook refused or did not answer; retry | No |

### 💰 Pricing

| Event | Price |
|---|---|
| Post returned (`post-scraped`) | **$0.0024** ($2.40 per 1,000) |
| Post details add-on (`post-details`) | $0.001 per post that receives details |

No start fee. Nothing is charged for `4xx` or `503` answers.

### 🗃️ Batch runs (input interface)

You can also start the actor as a normal run with a list of searches: monitor mode, long date-range backfills with
resume, and one dataset row per post, exactly like a batch scraper. Use the HTTP endpoint for one search at a time.

### ⏱️ Speed (measured on Apify, 2026-11-18)

- 3 posts: 4-5 s; 10 posts: 5-8 s; 50 posts: 45-75 s (Facebook serves 5-6 posts a page)
- First request after a quiet spell: add 5-10 s while the server starts and opens a Facebook session
- 4 searches in parallel: all answered, 5.6-7.5 s each

### ⚠️ Limits

- Facebook's search is fuzzy: it can return posts that do not contain your words. Use `mustContainQuery` or
  `keywordFilter` to keep only exact matches.
- Signed-out search only sees public posts, in the order Facebook serves them; it is not every post ever made.
- A request reads at most 3 pages more than the posts it returns, so very narrow filters can end with fewer posts than
  `maxPosts` (or a `404`); continue with `meta.nextCursor`.
- 50 posts per request; page further with the cursor.

### ❓ FAQ

#### Do I need a Facebook account or cookies?

No. The actor uses Facebook's public search the way a signed-out visitor does. You only need your Apify token.

#### What does a search cost?

$0.0024 per post returned, so a 10-post search is $0.024. A search that returns nothing is free.

#### How do I get more than 50 posts?

Repeat the request with `cursor` set to the previous response's `meta.nextCursor`.

#### Can I search a hashtag?

Yes: `query=#vegan`, or paste the `facebook.com/hashtag/vegan` URL.

#### Can I get only recent posts?

`sortBy=recent` for newest first, and `startDate=7 days` (or a date) to bound the window.

#### Why do some posts not contain my keyword?

Facebook's own search matches loosely. `mustContainQuery=true` keeps only posts whose text contains the query.

#### Does it return comments?

The top public comments, with `includePostDetails=true` (charged $0.001 per post that gets them).

#### How do I use it from an AI agent?

Point an MCP client at `https://topapi--facebook-posts-search-api.apify.actor/mcp` with your Apify token, or add it
through `mcp.apify.com`. The tool is `search_posts`; `compact: true` keeps answers short.

#### How do I use it in n8n or Make?

One HTTP Request step with `query` and your token in the `Authorization` header.

#### What if Facebook refuses a request?

You get a `503` and pay nothing. The actor already retries on fresh exits, so a retry a moment later usually works.

#### Your feedback

Open an issue on the actor page with the request you sent and the response you got.

# Actor input Schema

## `searchQueries` (type: `array`):

Keywords, phrases or hashtags, one per line, e.g. "coffee", "#blackfriday", "iPhone 17 battery". A Facebook search URL such as https://www.facebook.com/search/posts/?q=coffee also works. Facebook's search is fuzzy: it ranks related posts, so turn on 'Only posts that contain the query' for strict results.

## `sortBy` (type: `string`):

"Top" is Facebook's default ranking (popular posts, any age). "Most recent first" returns the newest public posts and pairs with monitor mode for a feed of new mentions.

## `startDate` (type: `string`):

Absolute date (2026-09-01) or relative to now (7 days, 3 weeks, 2 months, 1 year) or a day count (1 = today, 2 = yesterday and today). Sent to Facebook as its date filter and re-checked on every post. Leave empty for no lower bound.

## `endDate` (type: `string`):

Absolute date or relative (e.g. 30 days). A date includes that whole day. Combine with 'Posted after' for a window such as startDate 2026-01-01 + endDate 2026-06-30, or the same date in both for a single day.

## `locationUid` (type: `string`):

Facebook's numeric id of a city or region to restrict the search to posts tagged there, e.g. 108424279189115 (New York, NY). Find it on facebook.com: search, open the city filter and copy the number at the end of the location page URL. Leave empty for a global search.

## `mustContainQuery` (type: `boolean`):

Keep only posts whose text contains the search query (case-insensitive). Facebook's search also returns related posts without the exact words; this makes the result strict. Measured on 307 posts: single words matched 94% (coffee, pizza), multi-word phrases far less ("hiring now apply" 0%, "zillow listing" 40%).

## `keywordFilter` (type: `string`):

Keep only posts whose text, author name or link title contain this word or phrase, case-insensitive, e.g. "recipe" or "discount, sale, promo" (comma = any of them). Leave empty for no filter.

## `postType` (type: `string`):

Keep only one kind of post. Marketplace listings and event posts count as 'photo' when they carry an image.

## `postSource` (type: `string`):

Where the post was published. Measured on 307 search results: 25% were public-group posts, 4% came from business Pages, the rest from profiles and creator pages.

## `minReactions` (type: `integer`):

Keep only posts with at least this many reactions, e.g. 100 to keep popular posts only. 0 = no minimum.

## `includePostDetails` (type: `boolean`):

Opens each post's public page and adds the top comments Facebook shows signed-out (up to about 10: text, author, date, reactions), the video SD/HD file URLs and the video view count. Charged as the post-details event only for posts that received details. About one extra request (0.8 MB) per post.

## `monitorMode` (type: `boolean`):

Remembers, per search query, which posts were already delivered (in the named key-value store below) and returns only new ones. Works best with 'Most recent first': the run stops as soon as a whole page was already checked, so a scheduled check costs one or two pages. A run that finds nothing new delivers nothing. On schedules faster than hourly, a query is checked on every run while it brings new posts; after two checks in a row with nothing new it is checked every 15 minutes, then every 30, then every hour, until a new post resets it (hourly or slower schedules are checked on every run).

## `monitorStoreName` (type: `string`):

Name of the key-value store that keeps the per-query memory for monitor mode. Give each separate feed (a brand, a client, a Slack channel) its own name so they do not hide posts from each other. Letters, digits and hyphens.

## `checkEveryQuery` (type: `boolean`):

For long backfills and for monitoring on fast schedules, where every search must be read in full. Switches off the quiet-query pacing and the rule that a run reads further only from what it delivers: every query is read on every run, and each search page read is charged as a 'Search page read' event (Pricing tab) on top of the posts delivered, whether or not its posts fall inside your dates and filters. Off by default, so nothing changes unless you turn it on. Control the cost with 'Max posts per query' or 'Max pages per query per run' (how deep each run reads) and your schedule (how often).

## `resumeStoreName` (type: `string`):

Leave empty for a normal run. Give a name (letters, digits, hyphens) to let a search continue across runs: each query's position is saved in a key-value store of that name, and the next run with the same queries, sort, dates and filters carries on after the last page it finished. A query Facebook ran out of is not read again. Posts delivered by earlier runs are not delivered or charged twice. Use fixed dates (2026-06-01), not relative ones (7 days), so the window stays the same between runs. Not used in monitor mode.

## `sliceBy` (type: `string`):

Facebook serves a limited list of posts per search, so a long date range in one search returns a fraction of it. Pick month, week or day and each query is searched once per window of the range ('Posted after' to 'Posted before'); every row then carries search_window. Needs 'Posted after'; not used in monitor mode. Use with 'Top' (Facebook's recent list starts at today whatever the window) and with a resume memory name, so a long job continues across runs. Each run writes a COVERAGE record: per query and window, finished or not.

## `maxPagesPerSlice` (type: `integer`):

Search pages read for one query (one query and window when searching by month/week/day) during one run; a page holds 5-6 posts. With a resume memory name the search continues from there on the next run. 0 = no limit.

## `maxPostsPerQuery` (type: `integer`):

Cap per search query after filters (your main cost control; you pay per delivered post). Facebook serves 11-12 posts per page; deep pagination measured to 8+ pages. 0 = as many as Facebook serves, up to 1,000 per query.

## `maxItems` (type: `integer`):

Hard cap for the whole run across all queries. 0 = no total cap (each query is still capped above).

## `compact` (type: `boolean`):

Core fields only (post_id, type, url, message, published_at, author name/url/type, reactions, comments, shares, views, image, video, external_url, group, location, hashtags, search_query): about a fifth of the bytes, sized for AI agents and MCP clients.

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

Apify datacenter proxies by default. Facebook now answers the search itself only to residential addresses, so the actor opens its session on the datacenter group and moves the search pages to Apify RESIDENTIAL the moment Facebook refuses them (included in the price; no setting needed). Your own proxy URLs, if given, are used for everything.

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

Kept for compatibility. The actor reads all queries in parallel on its own (up to 6 at 128 MB, 10 at 256 MB), so this value no longer changes a run.

## Actor input object example

```json
{
  "searchQueries": [
    "coffee"
  ],
  "sortBy": "top",
  "mustContainQuery": false,
  "keywordFilter": "",
  "postType": "all",
  "postSource": "all",
  "minReactions": 0,
  "includePostDetails": false,
  "monitorMode": false,
  "monitorStoreName": "facebook-search-posts-monitor",
  "checkEveryQuery": false,
  "sliceBy": "none",
  "maxPagesPerSlice": 0,
  "maxPostsPerQuery": 12,
  "maxItems": 0,
  "compact": false,
  "proxyConfiguration": {
    "useApifyProxy": true
  },
  "maxConcurrency": 2
}
```

# Actor output Schema

## `posts` (type: `string`):

The dataset of Facebook posts found by the search (one item per post).

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

Per-query counts (read, filtered, already delivered, delivered), pages, requests made, sessions used and bytes transferred. Written for runs started in the Console, runs of 50+ posts and runs with a problem; small API, scheduled and webhook runs report the same counts in their status message and log.

# 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 = {
    "searchQueries": [
        "coffee"
    ],
    "maxPostsPerQuery": 12
};

// Run the Actor and wait for it to finish
const run = await client.actor("topapi/facebook-posts-search-api").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 = {
    "searchQueries": ["coffee"],
    "maxPostsPerQuery": 12,
}

# Run the Actor and wait for it to finish
run = client.actor("topapi/facebook-posts-search-api").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 '{
  "searchQueries": [
    "coffee"
  ],
  "maxPostsPerQuery": 12
}' |
apify call topapi/facebook-posts-search-api --silent --output-dataset

```

## MCP server setup

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

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/InNjrbuGhZ4BQxdqU/builds/dv2c8TaYuEAdnwJRT/openapi.json
