YouTube 發佈

了解如何連結 YouTube 頻道,並上傳包含中繼資料與自訂縮圖的影片。

連結 YouTube 頻道

前置需求

連結步驟

  1. 在控制台按下 「Connect YouTube」
  2. 如未登入 Google,請先登入
  3. 選擇要連結的 YouTube 頻道
  4. 檢視並授予必要權限
    • youtube.upload:上傳影片
    • youtube:管理頻道
    • youtube.readonly:讀取頻道資訊
  5. 點擊 「Allow」 完成授權

完成後,頻道會出現在「Authorized Accounts」列表,顯示:

權杖資訊

支援的內容類型

YouTube 支援附帶豐富中繼資料的影片上傳:

功能 說明 是否必填 限制
影片 影片檔案 URL MP4、MOV、AVI…
標題 影片標題 最多 100 字元
描述 影片描述 最多 5,000 字元
標籤 關鍵字 最多 500 個
縮圖 自訂縮圖 JPG、PNG(建議 1280x720)
隱私 公開權限 預設為 public

發佈範例

1. 基本影片(只有標題)

{
  "post": {
    "accountId": "your-youtube-channel-account-id",
    "content": {
      "text": "My Awesome Video Title",
      "mediaUrls": ["https://example.com/video.mp4"],
      "platform": "youtube"
    },
    "target": {
      "targetType": "youtube"
    }
  }
}

效果:僅設定標題的影片上傳。

2. 影片 + 標題與描述

text 欄位使用 \n\n(兩個換行)來分隔標題與描述:

{
  "post": {
    "accountId": "your-youtube-channel-account-id",
    "content": {
      "text": "Complete Guide to API Integration\n\nIn this comprehensive tutorial, we'll walk through the entire process of integrating our API into your application. Perfect for beginners and advanced developers alike!\n\n#API #Tutorial #Programming",
      "mediaUrls": ["https://example.com/tutorial-video.mp4"],
      "platform": "youtube"
    },
    "target": {
      "targetType": "youtube"
    }
  }
}

文字格式

效果

3. 影片 + 自訂縮圖

mediaUrls 第二個元素可提供縮圖:

{
  "post": {
    "accountId": "your-youtube-channel-account-id",
    "content": {
      "text": "Product Launch Event 2025\n\nJoin us for the biggest product launch of the year! See all the new features and innovations we've been working on. Don't miss out! #ProductLaunch #Tech #Innovation",
      "mediaUrls": [
        "https://storage.example.com/launch-video.mp4",
        "https://storage.example.com/thumbnail.jpg"
      ],
      "platform": "youtube"
    },
    "target": {
      "targetType": "youtube"
    }
  }
}

mediaUrls 陣列

API 請求範例

Python 範例

import requests

API_URL = "https://boring.aiagent-me.com/v2/posts"
API_KEY = "boring_xxxxxxxxxxxxx"
ACCOUNT_ID = "your-youtube-channel-account-id"

post_data = {
    "post": {
        "accountId": ACCOUNT_ID,
        "content": {
            "text": "Product Demo 2025\n\nFull walkthrough of the new features. #ProductDemo #SaaS",
            "mediaUrls": [
                "https://storage.example.com/demo-video.mp4",
                "https://storage.example.com/demo-thumbnail.jpg"
            ],
            "platform": "youtube"
        },
        "target": {
            "targetType": "youtube"
        }
    }
}

headers = {
    "boring-api-key": API_KEY,
    "Content-Type": "application/json"
}

response = requests.post(API_URL, headers=headers, json=post_data)
result = response.json()

if result.get("success"):
    print("Video uploaded successfully!")
    print(f"Video ID: {result['video_id']}")
    print(f"Watch at: {result['video_url']}")
    print(f"Thumbnail uploaded: {result.get('thumbnail_uploaded', False)}")
else:
    print(f"Upload failed: {result.get('error')}")

成功回應

{
  "success": true,
  "message": "Post published successfully",
  "postSubmissionId": "uuid-here",
  "platform": "youtube",
  "post_type": "video",
  "video_id": "dQw4w9WgXcQ",
  "video_url": "https://www.youtube.com/watch?v=dQw4w9WgXcQ",
  "thumbnail_uploaded": true
}

文字格式指南

使用 \n\n 分隔

text 欄位中的 \n\n 用於分隔標題與描述。

❌ 錯誤:只有單個換行 \n

{
  "text": "My Title\nMy Description"
}

效果:整段文字皆視為標題,描述為空。

✅ 正確:使用雙換行 \n\n

{
  "text": "My Title\n\nMy Description"
}

效果:

各語言示例

Python

text = "Video Title\n\nThis is the description with #hashtags"

# 或使用三引號讓內容可讀性更高
text = """Video Title

This is the description with #hashtags"""

JavaScript

const text = "Video Title\n\nThis is the description with #hashtags";

// 或使用模板字面值
const text = `Video Title

This is the description with #hashtags`;

cURL

curl -X POST https://boring.aiagent-me.com/v2/posts \
  -H "boring-api-key: boring_xxxxx" \
  -H "Content-Type: application/json" \
  -d '{
    "post": {
      "accountId": "your-account-id",
      "content": {
        "text": "Video Title\n\nVideo description here",
        "mediaUrls": ["https://example.com/video.mp4"],
        "platform": "youtube"
      },
      "target": {"targetType": "youtube"}
    }
  }'

影片需求

支援格式

檔案規格

上傳流程

  1. 下載:從提供的 URL 下載影片
  2. 上傳:使用可續傳上傳(resumable upload)
  3. 處理:YouTube 進行轉碼與處理
  4. 縮圖:若提供縮圖則上傳
  5. 發佈:依隱私設定公開

伺服器日誌範例

[YOUTUBE] Upload progress: 33%
[YOUTUBE] Upload progress: 67%
[YOUTUBE] Upload progress: 100%
[YOUTUBE] Video uploaded successfully! Video ID: abc123
[YOUTUBE] Thumbnail uploaded successfully

隱私設定

目前影片預設為 public。未來版本規劃支援:

疑難排解

常見錯誤

錯誤:「Video URL is required」

錯誤:「Failed to download video」

錯誤:「YouTube service not initialized」

錯誤:「Thumbnail upload failed」

上傳時間過久?

上傳時間取決於:

參考時間

最佳實務

  1. 先用小型影片測試:確認流程無誤
  2. 使用穩定雲端託管:建議 GCS、S3…等
  3. 優化影片檔案:使用 H.264 編碼並適度壓縮
  4. 設計吸睛縮圖:1280x720、亮眼配色、清晰文字
  5. 撰寫 SEO 友善描述:置入關鍵字
  6. 善用 Hashtag:描述中加入 3-5 個相關標籤
  7. 監控上傳狀態:在控制台查看錯誤訊息

發佈歷史

在控制台檢視所有 YouTube 上傳紀錄:

  1. 登入 Boring 控制台
  2. 捲動至 「Recent Posts」 區塊
  3. 篩選平台為 YouTube

每筆紀錄顯示:

速率限制

YouTube API 配額規則:

每日可容量:預設配額約可上傳 6 支影片

若需更高配額,可於 Google Cloud Console 申請。

Boring 會妥善處理配額不足的錯誤並回傳對應訊息。

進階功能

多個頻道

同一個 Boring 帳號可連結多個 YouTube 頻道,每個頻道都有獨立帳號 ID。

操作流程

  1. 連結頻道 A,取得帳號 ID:aaa-111
  2. 連結頻道 B,取得帳號 ID:bbb-222
  3. 使用 accountId: "aaa-111" 上傳至頻道 A
  4. 使用 accountId: "bbb-222" 上傳至頻道 B

批次上傳

透過程式批次上傳多支影片:

videos = [
    {
        "title": "Episode 1: Introduction",
        "description": "Welcome to our series!",
        "video_url": "https://example.com/ep1.mp4",
        "thumbnail_url": "https://example.com/ep1-thumb.jpg"
    },
    {
        "title": "Episode 2: Getting Started",
        "description": "Let's dive deeper!",
        "video_url": "https://example.com/ep2.mp4",
        "thumbnail_url": "https://example.com/ep2-thumb.jpg"
    }
]

for video in videos:
    post_data = {
        "post": {
            "accountId": ACCOUNT_ID,
            "content": {
                "text": f"{video['title']}\n\n{video['description']}",
                "mediaUrls": [video['video_url'], video['thumbnail_url']],
                "platform": "youtube"
            },
            "target": {"targetType": "youtube"}
        }
    }

    response = requests.post(API_URL, headers=headers, json=post_data)
    print(f"Uploaded: {video['title']} - {response.json()}")

    # 間隔上傳避免配額限制
    time.sleep(60)

速查表

最精簡上傳(標題 + 影片)

{
  "post": {
    "accountId": "your-account-id",
    "content": {
      "text": "Video Title",
      "mediaUrls": ["https://example.com/video.mp4"],
      "platform": "youtube"
    },
    "target": {"targetType": "youtube"}
  }
}

完整上傳(標題 + 描述 + 縮圖)

{
  "post": {
    "accountId": "your-account-id",
    "content": {
      "text": "Video Title\n\nDetailed description with #tags",
      "mediaUrls": [
        "https://example.com/video.mp4",
        "https://example.com/thumbnail.jpg"
      ],
      "platform": "youtube"
    },
    "target": {"targetType": "youtube"}
  }
}

下一步