# YouTube Channel Stats & Video Performance (`accommodating_aptitude/youtube-channel-stats`) Actor

Channel statistics via the official YouTube Data API v3: subscriber count, video count, total views, country, creation date, plus view/like/comment performance of recent videos and the engagement rate. Bring your own free API key (BYOK), ~3 quota units per channel.

- **URL**: https://apify.com/accommodating_aptitude/youtube-channel-stats.md
- **Developed by:** [Korhan Coşan Ergün](https://apify.com/accommodating_aptitude) (community)
- **Features:** Limited permissions
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

$4.00 / 1,000 channel founds

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

## YouTube Channel Stats & Video Performance

Channel statistics and recent-video performance via the official **YouTube Data
API v3**.

### Bring your own API key (BYOK)

The `youtubeApiKey` input is **required** and is stored as a secret. To get one
for free:

1. [console.cloud.google.com](https://console.cloud.google.com) → new project
2. **APIs & Services → Library** → "YouTube Data API v3" → **Enable**
3. **APIs & Services → Credentials → Create credentials → API key**

You get a free quota of **10,000 units per day**. This actor picks the
quota-friendly endpoints:

| Call | Quota | Used for |
|---|---|---|
| `channels.list` | 1 | Channel statistics |
| `playlistItems.list` | 1 | Recent videos from the channel's "uploads" playlist |
| `videos.list` | 1 | Statistics for 50 videos in a single call |
| `search.list` | 100 | **Only** as a last resort when a handle/ID cannot be resolved at all |

A channel + its last 5 videos ≈ **3 units** → the free quota is enough for
**~3,000 channels per day**.

### Input

```json
{
  "youtubeApiKey": "***",
  "channels": ["https://www.youtube.com/@GoogleDevelopers", "UC_x5XG1OV2P6uZZ5FSM9Ttw"],
  "includeRecentVideos": true,
  "recentVideoCount": 5
}
```

Accepted channel formats: `UC...` ID, `@handle`, `youtube.com/@handle`,
`youtube.com/channel/UC...`, `/c/...`, `/user/...`

### Output fields

| Field | Description |
|---|---|
| `channel_id`, `channel_title`, `custom_url`, `handle_url` | Identity and links |
| `subscriber_count`, `hidden_subscriber_count` | Subscriber count (with a flag if the channel hides it) |
| `video_count`, `view_count`, `avg_views_per_video` | Total videos/views and the lifetime average |
| `published_at`, `country`, `description`, `keywords`, `topic_categories` | Channel profile |
| `uploads_playlist_id`, `thumbnail_url`, `privacy_status` | Technical fields |
| `recent_videos[]` | `{video_id, title, link, published_at, view_count, like_count, comment_count, duration_seconds, thumbnail_url}` |
| `recent_video_count`, `recent_avg_views` | Average views of the recent videos |
| `recent_engagement_rate` | `recent_avg_views / subscriber_count * 100` (%) — a channel health indicator |
| `error` | Error for this channel (if any), otherwise `null` |

### Pricing

Pay-per-event: **`channel-found` → $0.004**. You are only charged when a channel
is actually found.

### Local test

```bash
bash ../_common/vendor_common.sh .
APIFY_LOCAL=1 YOUTUBE_API_KEY=*** python3 main.py
```

Without a key (code-path verification only):

```bash
python3 test_fixtures.py
```

> `test_fixtures.py` starts a local HTTP server that imitates the API. The
> response bodies are written to match the field structure in Google's official
> API reference: **structurally correct, but the data is synthetic.** It verifies
> the parsing/normalization/dataset-writing paths, not the live API.
> `sample_output.json` is also derived from that fixture run (an example
> structure, not live data).

# Actor input Schema

## `youtubeApiKey` (type: `string`):

Your own free key. How to get it: console.cloud.google.com -> APIs & Services -> Library -> 'YouTube Data API v3' -> Enable -> Credentials -> Create credentials -> API key. It gives a free quota of 10,000 units per day; this actor spends only ~3 units per channel (so ~3,000 channels per day). Alternatively it can be set as the actor environment variable YOUTUBE_API_KEY; if left empty, the actor logs the key-acquisition instructions and finishes with an empty result.

## `channels` (type: `array`):

The channels to analyse. Accepted formats: UC... channel ID, @handle, https://youtube.com/@handle, https://youtube.com/channel/UC..., /c/... and /user/... URLs.

## `includeRecentVideos` (type: `boolean`):

When enabled, the channel's recent videos are pulled from its 'uploads' playlist, and view/like/comment counts plus average views and the engagement rate are computed.

## `recentVideoCount` (type: `integer`):

How many recent videos to pull per channel (every 50 videos costs ~2 quota units).

## Actor input object example

```json
{
  "channels": [
    "https://www.youtube.com/@GoogleDevelopers"
  ],
  "includeRecentVideos": true,
  "recentVideoCount": 5
}
```

# Actor output Schema

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

Dataset containing all records found in this run.

# 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 = {
    "channels": [
        "https://www.youtube.com/@GoogleDevelopers"
    ]
};

// Run the Actor and wait for it to finish
const run = await client.actor("accommodating_aptitude/youtube-channel-stats").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 = { "channels": ["https://www.youtube.com/@GoogleDevelopers"] }

# Run the Actor and wait for it to finish
run = client.actor("accommodating_aptitude/youtube-channel-stats").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 '{
  "channels": [
    "https://www.youtube.com/@GoogleDevelopers"
  ]
}' |
apify call accommodating_aptitude/youtube-channel-stats --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,accommodating_aptitude/youtube-channel-stats"
        }
    }
}
```

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/gieFkb8o7NSMcGiPV/builds/UoifkBego2C2pRmGN/openapi.json
