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

# 从频道URL获取频道ID

> 从YouTube频道URL转换获取频道ID（channel_id）。
支持多种URL格式，包括@用户名格式、/channel/格式、/c/格式、/user/格式。

<div className="inline-flex items-center gap-2 px-4 py-2 bg-yellow-50 dark:bg-yellow-900/20 border border-yellow-200 dark:border-yellow-800 rounded-lg">
  <span className="text-base">🪙</span>
  <span className="text-sm font-medium text-yellow-900 dark:text-yellow-100"><span className="font-semibold">3 credits</span><span className="text-yellow-700 dark:text-yellow-300 ml-1">每次请求</span></span>
</div>

## Copy for AI

<div className="my-6 rounded-xl border border-gray-200 bg-gray-50 p-5 dark:border-gray-800 dark:bg-gray-900/40">
  <div className="min-w-0">
    <p className="text-base font-semibold text-gray-900 dark:text-gray-100">🤖 让 AI 帮你写调用代码</p>
    <p className="mt-1 text-sm text-gray-700 dark:text-gray-300">点击按钮复制一段结构化提示词，可直接交给 ChatGPT、Claude 或其他 AI 助手生成接口调用代码。</p>
  </div>

  <div className="mt-4">
    <button type="button" className="inline-flex items-center gap-2 rounded-md border border-emerald-300 bg-emerald-50 px-3 py-2 text-sm font-medium text-emerald-800 hover:bg-emerald-100 dark:border-emerald-700 dark:bg-emerald-900/30 dark:text-emerald-100 dark:hover:bg-emerald-900/50" onClick={() => navigator.clipboard.writeText("我想调用 KeyAPI 接口：GET https://api.keyapi.ai/v1/youtube/get_channel_id_from_url\n\n请帮我编写调用代码，并包含必要的错误处理、参数校验和响应处理逻辑。\n\n接口信息：\n\nEndpoint: GET https://api.keyapi.ai/v1/youtube/get_channel_id_from_url\n\nDescription: YouTube 的「从 URL 解析频道 ID」接口用于根据指定标识查询完整信息，返回基础资料、统计指标以及示例中的扩展字段。常用必填参数包括 channel_url。\n\nRequired Headers:\n--header 'Authorization: Bearer <YOUR_API_KEY>'\n\nParameters:\n- channel_url (Required): channel_url 参数. Example: https://www.youtube.com/@CozyCraftYT\n\nExample Response:\n{\n  \"code\": 0,\n  \"message\": \"success\",\n  \"data\": {\n    \"channel_id\": \"UCeu6U67OzJhV1KwBansH3Dg\",\n    \"channel_url\": \"https://www.youtube.com/channel/UCeu6U67OzJhV1KwBansH3Dg\"\n  },\n  \"requestId\": \"91bf1793-f8ee-49a9-bebe-7c2fe1808076\"\n}\n\n请根据以上信息给出可直接运行的示例代码。")}>
      ✨ 复制给 AI
    </button>
  </div>
</div>


## OpenAPI

````yaml zh/youtube.zh.openapi.json GET /v1/youtube/get_channel_id_from_url
openapi: 3.0.1
info:
  title: YouTube API 中文文档
  description: YouTube API 的中文参考文档，包含接口用途、参数说明、响应状态和示例结构。
  version: 1.0.0
servers:
  - url: https://api.keyapi.ai
    description: Production
security: []
tags: []
paths:
  /v1/youtube/get_channel_id_from_url:
    get:
      tags: []
      summary: 从频道URL获取频道ID
      description: |-
        从YouTube频道URL转换获取频道ID（channel_id）。
        支持多种URL格式，包括@用户名格式、/channel/格式、/c/格式、/user/格式。
      parameters:
        - name: channel_url
          in: query
          description: >-
            Channel URL

            Supports multiple formats such as:

            https://www.youtube.com/@username,
            https://www.youtube.com/channel/UCxxxxxx,
            https://www.youtube.com/c/channelname
          required: true
          example: https://www.youtube.com/@CozyCraftYT
          schema:
            type: string
            example: https://www.youtube.com/@CozyCraftYT
      responses:
        '200':
          description: 请求成功
          content:
            application/json:
              schema:
                type: object
                properties: {}
              example:
                code: 0
                message: success
                data:
                  channel_id: UCeu6U67OzJhV1KwBansH3Dg
                  channel_url: https://www.youtube.com/channel/UCeu6U67OzJhV1KwBansH3Dg
                requestId: 91bf1793-f8ee-49a9-bebe-7c2fe1808076
          headers: {}
        '400':
          description: 请求参数错误，请检查必填字段和参数格式
          content:
            application/json:
              schema:
                type: object
                example:
                  code: 400
                  data: null
                  message: 'Missing required parameter: handle'
        '401':
          description: 鉴权失败，请检查 Authorization Header 中的 Bearer Token 或 API Key 是否有效
          content:
            application/json:
              schema:
                type: object
                example:
                  code: 401
                  data: null
                  message: apiKey is null
        '402':
          description: 账户余额或额度不足
          content:
            application/json:
              schema:
                type: object
                example:
                  code: 402
                  data: null
                  message: apiKey quota is not enough
        '429':
          description: 请求过于频繁，已触发限流
          content:
            application/json:
              schema:
                type: object
                example:
                  code: 429
                  data: null
                  message: qps limit exceeded
        '500':
          description: 服务器内部错误，请稍后重试
          content:
            application/json:
              schema:
                type: object
                example:
                  code: 500
                  data: null
                  message: Internal server error
      deprecated: false
      security:
        - JWT Bearer: []
      x-codeSamples:
        - lang: curl
          label: cURL
          source: |-
            curl --request GET \
              --url 'https://api.keyapi.ai/v1/youtube/get_channel_id_from_url?channel_url=https%3A%2F%2Fwww.youtube.com%2F%40CozyCraftYT' \
              --header 'Authorization: Bearer <YOUR_API_KEY>'
        - lang: python
          label: Python
          source: |-
            import requests

            response = requests.get(
                'https://api.keyapi.ai/v1/youtube/get_channel_id_from_url',
                params={"channel_url": "https://www.youtube.com/@CozyCraftYT"},
                headers={'Authorization': 'Bearer <YOUR_API_KEY>'}
            )
            print(response.json())
        - lang: javascript
          label: JavaScript
          source: >-
            const params = new URLSearchParams({"channel_url":
            "https://www.youtube.com/@CozyCraftYT"});


            const response = await
            fetch(`https://api.keyapi.ai/v1/youtube/get_channel_id_from_url?${params}`,
            {
              method: 'GET',
              headers: { 'Authorization': 'Bearer <YOUR_API_KEY>' }
            });

            const data = await response.json();

            console.log(data);
components:
  securitySchemes:
    JWT Bearer:
      type: http
      scheme: bearer
      bearerFormat: JWT
      description: |-
        接口鉴权凭证。请在请求 Header 中传入 `Authorization: Bearer <YOUR_API_KEY>`。
        可在 [Dashboard](https://keyapi.ai/app/dashboard) 获取你的 API Key。

````