# Mastodon Public Posts & Hashtag Scraper (`mellora/mastodon-public-posts-scraper`) Actor

Collect public posts, hashtag timelines and profile posts from Mastodon instances via their open JSON endpoints, with no login.

- **URL**: https://apify.com/mellora/mastodon-public-posts-scraper.md
- **Developed by:** [James Barnes](https://apify.com/mellora) (community)
- **Categories:** Social media
- **Security:** Limited permissions
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

$1.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?

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

## Mastodon Public Posts & Hashtag Scraper

Monitor a hashtag, track a profile or sample an instance's public timeline on Mastodon, and get clean structured data with no login and no API key. It reads the open JSON endpoints that Mastodon servers expose to logged-out visitors.

### Sample output

```json
{
    "id": "112233445566778899",
    "url": "https://mastodon.social/@Gargron/112233445566778899",
    "instance": "mastodon.social",
    "created_at": "2024-05-01T12:34:56.000Z",
    "language": "en",
    "text": "Example post text about #opensource",
    "spoiler_text": null,
    "sensitive": false,
    "author_username": "Gargron",
    "author_acct": "Gargron",
    "author_display_name": "Eugen Rochko",
    "author_url": "https://mastodon.social/@Gargron",
    "author_followers": 300000,
    "replies_count": 12,
    "reblogs_count": 30,
    "favourites_count": 85,
    "hashtags": ["opensource"],
    "media": [],
    "is_reply": false,
    "boosted_by": null
}
```

(Values above are illustrative of the format.)

### Use cases

- Brand and topic monitoring through hashtags
- Research on discussions in the fediverse
- Tracking public posts from specific accounts
- Building datasets of public posts with engagement counts

### Input

| Field | Description |
|---|---|
| `mode` | `public_timeline`, `hashtag` or `profile` |
| `instance` | Server domain, e.g. `mastodon.social` |
| `hashtags` | Hashtags without `#` (hashtag mode) |
| `profiles` | Handles like `Gargron` (profile mode) |
| `maxResults` | Total posts to collect (up to 5000) |
| `localOnly` | Only posts created on that instance |
| `excludeReplies` / `excludeReblogs` | Filter replies or boosts |
| `minFavourites` | Minimum favourites per post |

### Pricing

$0.001 per result (per post saved to the dataset). 1,000 posts cost $1.

### Limits

- Only public data visible to logged-out visitors is read.
- Some instances disable public timelines or hashtag access without login; those return no results and a warning is logged.
- A hashtag or timeline only shows posts known to the chosen instance, so different instances return different sets.
- Requests are paced at about one per second, with backoff on rate limiting (429).
- No CAPTCHAs are solved and no private contact details are collected.
- Maximum 5000 posts per run.

# Actor input Schema

## `mode` (type: `string`):

What to collect: the instance's public timeline, posts for hashtags, or posts from specific profiles.

## `instance` (type: `string`):

Mastodon server domain to read from, e.g. mastodon.social. Hashtag and timeline results reflect what that server has seen.

## `hashtags` (type: `array`):

Hashtags to collect (without #). Used in 'Hashtag timelines' mode.

## `profiles` (type: `array`):

Handles such as Gargron or Gargron@mastodon.social. Used in 'Profile posts' mode. Resolved on the chosen instance.

## `maxResults` (type: `integer`):

Maximum number of posts to collect in total (cap 5000).

## `localOnly` (type: `boolean`):

Only posts created on the chosen instance (timeline and hashtag modes).

## `excludeReplies` (type: `boolean`):

Skip posts that are replies.

## `excludeReblogs` (type: `boolean`):

Skip boosted (reblogged) posts.

## `minFavourites` (type: `integer`):

Only keep posts with at least this many favourites.

## Actor input object example

```json
{
  "mode": "hashtag",
  "instance": "mastodon.social",
  "hashtags": [
    "opensource"
  ],
  "profiles": [
    "Gargron"
  ],
  "maxResults": 50,
  "localOnly": false,
  "excludeReplies": false,
  "excludeReblogs": false,
  "minFavourites": 0
}
```

# 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 = {
    "mode": "hashtag",
    "instance": "mastodon.social",
    "hashtags": [
        "opensource"
    ],
    "profiles": [
        "Gargron"
    ],
    "maxResults": 50
};

// Run the Actor and wait for it to finish
const run = await client.actor("mellora/mastodon-public-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 = {
    "mode": "hashtag",
    "instance": "mastodon.social",
    "hashtags": ["opensource"],
    "profiles": ["Gargron"],
    "maxResults": 50,
}

# Run the Actor and wait for it to finish
run = client.actor("mellora/mastodon-public-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 '{
  "mode": "hashtag",
  "instance": "mastodon.social",
  "hashtags": [
    "opensource"
  ],
  "profiles": [
    "Gargron"
  ],
  "maxResults": 50
}' |
apify call mellora/mastodon-public-posts-scraper --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,mellora/mastodon-public-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/YYqaTx3N0qtzppkAW/builds/FfHUHqb5BXMWXsvPK/openapi.json
