> ## Documentation Index
> Fetch the complete documentation index at: https://docs.brightdata.com/llms.txt
> Use this file to discover all available pages before exploring further.

# 发送您的第一个YouTube API请求

> 使用可复制粘贴的代码示例对所有三个Bright Data YouTube爬虫API端点进行同步请求。

本指南介绍如何向每个 Bright Data YouTube Scraper API 端点发送同步请求。完成后，您将获得频道、视频和评论的工作示例。

## 先决条件

* 一个 [Bright Data 账户](https://www.bright.cn/cp/start)，具有有效的 API 密钥
* 完成了 [快速入门](/cn/products/scrapers/youtube/quickstart)

## 请求结构

每个同步请求都遵循相同的模式：

```
POST https://api.brightdata.com/datasets/v3/scrape?dataset_id={DATASET_ID}&format=json
Authorization: Bearer YOUR_API_KEY
Content-Type: application/json

[{"url": "https://www.youtube.com/..."}]
```

端点之间唯一改变的是 `dataset_id` 和输入 URL 格式。

<Note>
  同步请求支持最多 20 个 URL，超时时间为 1 分钟。如果请求耗时较长，API 将自动返回 `snapshot_id`。请参阅 [异步请求](/cn/products/scrapers/scrapers-library/async-requests)。
</Note>

## 频道

**数据集 ID：** `gd_lk538t2k2p1k3oos71`

```bash theme={null}
curl -X POST \
  "https://api.brightdata.com/datasets/v3/scrape?dataset_id=gd_lk538t2k2p1k3oos71&format=json" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '[{"url": "https://www.youtube.com/@MrBeast"}]'
```

您应该会看到 `200` 响应。这需要 10-30 秒。

<Accordion title="示例响应">
  ```json theme={null}
  [
    {
      "channel_name": "MrBeast",
      "channel_url": "https://www.youtube.com/@MrBeast",
      "subscribers": 358000000,
      "total_videos": 850,
      "total_views": 50000000000,
      "description": "...",
      "is_verified": true
    }
  ]
  ```
</Accordion>

[完整频道响应架构](/cn/api-reference/scrapers/social-media-apis/youtube-channels-collect-by-url)

## 视频

**数据集 ID：** `gd_lk56epmy2i5g7lzu0k`

```bash theme={null}
curl -X POST \
  "https://api.brightdata.com/datasets/v3/scrape?dataset_id=gd_lk56epmy2i5g7lzu0k&format=json" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '[{"url": "https://www.youtube.com/watch?v=dQw4w9WgXcQ"}]'
```

<Accordion title="示例响应">
  ```json theme={null}
  [
    {
      "url": "https://www.youtube.com/watch?v=dQw4w9WgXcQ",
      "title": "Rick Astley - Never Gonna Give You Up",
      "channel_name": "Rick Astley",
      "views": 1500000000,
      "likes": 16000000,
      "date_posted": "2009-10-25T00:00:00.000Z",
      "duration": "3:33",
      "description": "...",
      "num_comments": 2700000
    }
  ]
  ```
</Accordion>

[完整视频响应架构](/cn/api-reference/scrapers/social-media-apis/youtube-videos-collect-by-url)

## 评论

**数据集 ID：** `gd_lk9q0ew71spt1mxywf`

```bash theme={null}
curl -X POST \
  "https://api.brightdata.com/datasets/v3/scrape?dataset_id=gd_lk9q0ew71spt1mxywf&format=json" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '[{"url": "https://www.youtube.com/watch?v=dQw4w9WgXcQ"}]'
```

<Accordion title="示例响应">
  ```json theme={null}
  [
    {
      "url": "https://www.youtube.com/watch?v=dQw4w9WgXcQ",
      "comment_user": "user123",
      "comment_user_url": "https://www.youtube.com/@user123",
      "comment_date": "2024-04-05T12:30:00.000Z",
      "comment": "This song never gets old!",
      "likes": 250,
      "replies": 12,
      "comment_id": "UgyKz0..."
    }
  ]
  ```
</Accordion>

[完整评论响应架构](/cn/api-reference/scrapers/social-media-apis/youtube-comments-collect-by-url)

## 快速参考：数据集 ID

| 端点 | 数据集 ID                  | URL 模式                           |
| :- | :---------------------- | :------------------------------- |
| 视频 | `gd_lk56epmy2i5g7lzu0k` | `youtube.com/watch?v={video_id}` |
| 频道 | `gd_lk538t2k2p1k3oos71` | `youtube.com/@{handle}`          |
| 评论 | `gd_lk9q0ew71spt1mxywf` | `youtube.com/watch?v={video_id}` |

## 输出格式

使用 `format` 查询参数控制响应格式：

| 值        | 描述                |
| :------- | :---------------- |
| `json`   | JSON 数组（默认）       |
| `ndjson` | 换行分隔的 JSON，每行一条记录 |
| `csv`    | 逗号分隔值             |

## 相关内容

<CardGroup cols={2}>
  <Card title="异步批量请求" icon="layer-group" href="/products/scrapers/scrapers-library/async-requests">
    在单个批量作业中抓取数百个 URL。
  </Card>

  <Card title="API 参考" icon="code" href="/api-reference/scrapers/social-media-apis/youtube-channels-collect-by-url">
    完整的参数和响应字段参考。
  </Card>
</CardGroup>
