# 影片號 API Python 教程：搜尋、作品、帳號和評論（2026）

> 用 Python 和 requests 讀影片號的公開資料：影片搜尋、作品詳情、帳號搜尋、帳號作品和評論，不用掃碼登入。ID 怎麼用、怎麼翻頁、完整程式碼和花費。

網頁版：https://okdata.online/zh-hant/guides/wechat-channels-api-python/

在 Python 裡用五個介面就夠：影片號影片搜尋、作品詳情、帳號搜尋、帳號作品和作品評論，每個都是帶 API key 的普通 HTTPS GET 請求，不用登入微信。下面的示例一共 6 次呼叫，花費 $0.11；請求到了平台的呼叫，返回為空、查不到或出錯也照常計費。

更新於 2026-11-12

影片號有沒有能讀別人影片的官方 API？沒有。微信開放文件裡影片號這一塊，講的是影片號小店、本地生活團購，以及影片號助手 API；影片號助手 API 讀的是你自己帳號的資料：直播記錄、櫥窗商品、留資、直播大屏和羅盤達人版的帶貨資料。小程式可以跳轉或內嵌一條影片號影片，用的是從影片號助手或 App 裡手動複製的 ID 或 token，作用是播放，不是返回資料。官方文件裡沒有任何介面能拿到別人帳號的影片、資料或評論。

所以大多數用 Python 抓影片號的專案，最後都繞回到一個登入著的微信會話上：手機掃碼，想辦法讓登入態別掉，讀資料用的那個微訊號還要自己承擔被風控的風險。這篇走另一條路：每次呼叫就是一個 HTTPS GET，請求頭裡帶 API key。不需要微信帳號，不用 Cookie，不用掃碼，也不用處理簽名，Python 裡只用到 `requests`。

## 分步操作

先在終端裡設好 key：`export OKDATA_API_KEY=okd_...`。所有介面的返回結構都一樣：成功時 `code` 是 `"ok"`；列表介面的結果在 `data.items`，翻頁資訊在 `page`；單個物件的介面，結果在 `data.item`。

### 第一步：按關鍵詞搜影片

[影片號影片搜尋](https://okdata.online/zh/apis/wechat_channels/videos/search/)的引數有 `query`，可選的 `sort`（預設 `relevance`，另有 `latest`、`popular`），以及可選的 `published_within`（`day`、`week` 或 `half_year`）。一次呼叫最多返回約 10 條影片，每次 $0.02：描述、釋出時間、帳號名稱和頭像、點贊數和封面。每條結果的 `id` 是 `export/` 開頭的加密 ID，會過期，想要的影片要在同一次執行裡查詳情。

```bash
curl -G "https://api.okdata.online/v1/wechat_channels/videos/search" -H "Authorization: Bearer $OKDATA_API_KEY" \
  --data-urlencode 'query=露營裝備' --data-urlencode 'sort=popular' --data-urlencode 'published_within=week'
```

### 第二步：查作品詳情

[影片號作品詳情](https://okdata.online/zh/apis/wechat_channels/videos/get/)接受數字作品 ID、搜尋結果的 `export/` ID，或者用 `url` 傳分享連結。每次 $0.02，返回數字 `id`、`author.id` 裡的帳號 ID、`metrics.likes`、`metrics.comments`、`metrics.shares`、`metrics.favorites`；加上 `view=full`，`ext` 裡還有位置和時長。

```bash
curl -G "https://api.okdata.online/v1/wechat_channels/videos/get" -H "Authorization: Bearer $OKDATA_API_KEY" \
  --data-urlencode 'url=https://weixin.qq.com/sph/AqR7tLm2Kd'
```

### 第三步：按名稱找帳號

[影片號帳號搜尋](https://okdata.online/zh/apis/wechat_channels/users/search/)的 `query` 填帳號名稱，走微信搜一搜，通常只返回最匹配的一個，每次 $0.02。返回的 `id` 是帳號 ID，格式是 `v2_…@finder`。App 裡顯示的 `sph` 開頭的影片號 ID 是另一回事，介面不認。

```bash
curl -G "https://api.okdata.online/v1/wechat_channels/users/search" -H "Authorization: Bearer $OKDATA_API_KEY" \
  --data-urlencode 'query=三聯生活週刊'
```

### 第四步：拉帳號作品

[影片號帳號作品](https://okdata.online/zh/apis/wechat_channels/users/videos/list/)的 `id` 填 `v2_…@finder`，按從新到舊返回，每頁約 15 條，每頁 $0.02，每條帶點贊、評論、轉發和收藏。影片號的影片沒有網頁，所以作品的 `url` 是加密的影片檔案，解密 key 在 `ext.decode_key`（需要 `view=full`）。

```bash
curl -G "https://api.okdata.online/v1/wechat_channels/users/videos/list" -H "Authorization: Bearer $OKDATA_API_KEY" \
  --data-urlencode 'id=v2_060000231003b20faec8c353a18ebca650858991e19fab55aa5e12f6d5010f5e0eeaaafc3520@finder'
```

### 第五步：讀評論

[影片號作品評論](https://okdata.online/zh/apis/wechat_channels/videos/comments/list/)要的是數字作品 ID（不是 `export/` 那個），每頁約 25 條一級評論，按熱度排，每次 $0.015：`text`、`author.name`、`likes`、`replies`、`published_at` 和 `ip_location`。翻頁時把上一次的 `page.next_cursor` 作為 `cursor` 傳回去。

```bash
curl -G "https://api.okdata.online/v1/wechat_channels/videos/comments/list" -H "Authorization: Bearer $OKDATA_API_KEY" \
  --data-urlencode 'id=14987320651142873906'
```

### 第六步：完整的 Python 指令碼

所有呼叫都走同一個函式：檢查 `body["code"]`，遇到已刪除的內容就跳過，遇到限流或平台繁忙就用同一個 `Idempotency-Key` 重試。限流那次不扣費；平台繁忙後的重試算新呼叫，會再計費一次。翻頁統一用一個帶頁數上限的生成器。結果寫進 `channels.json`。

```python
import json
import os
import time
import uuid

import requests

API = "https://api.okdata.online"
KEY = os.environ["OKDATA_API_KEY"]
COMMENT_PAGES = 2   # 每頁一次呼叫
VIDEO_PAGES = 1     # 每頁一次呼叫，約 15 條


class NotFound(Exception):
    pass


def call(path, **params):
    headers = {"Authorization": f"Bearer {KEY}", "Idempotency-Key": str(uuid.uuid4())}
    for attempt in range(4):
        body = requests.get(API + path, headers=headers, params=params, timeout=60).json()
        if body["code"] == "ok":
            return body
        if body["code"] == "not_found":
            raise NotFound(body["message"])  # 已刪除或不公開：照常計費，跳過即可
        if body.get("retry") in ("yes", "same_key"):
            time.sleep(body.get("retry_after_seconds") or 2 ** attempt)
            continue
        raise RuntimeError(f"{body['code']}: {body['message']} (request {body['request_id']})")
    raise RuntimeError(f"{path}: 重試 4 次仍然失敗")


def paged(path, max_pages, **params):
    cursor = None
    for _ in range(max_pages):
        body = call(path, **params, **({"cursor": cursor} if cursor else {}))
        yield from body["data"]["items"]
        if not body["data"]["items"] or not body["page"]["has_more"]:
            return
        cursor = body["page"]["next_cursor"]


def keyword_report(query):
    hits = call("/v1/wechat_channels/videos/search", query=query, sort="popular",
                published_within="week")["data"]["items"]
    if not hits:
        return None
    video = call("/v1/wechat_channels/videos/get", id=hits[0]["id"])["data"]["item"]
    comments = list(paged("/v1/wechat_channels/videos/comments/list", COMMENT_PAGES, id=video["id"]))
    return {"hits": hits, "video": video, "comments": comments}


def account_report(name):
    found = call("/v1/wechat_channels/users/search", query=name)["data"]["items"]
    if not found:
        return None
    account = found[0]
    videos = list(paged("/v1/wechat_channels/users/videos/list", VIDEO_PAGES, id=account["id"]))
    return {"account": account, "videos": videos}


if __name__ == "__main__":
    report = {}
    try:
        report["keyword"] = keyword_report("露營裝備")
    except NotFound:
        report["keyword"] = None  # 搜尋之後、查詳情之前，排第一的影片被刪了
    report["account"] = account_report("三聯生活週刊")
    with open("channels.json", "w", encoding="utf-8") as f:
        json.dump(report, f, ensure_ascii=False, indent=2)
    print("搜到影片：", len((report["keyword"] or {}).get("hits", [])),
          "| 評論：", len((report["keyword"] or {}).get("comments", [])),
          "| 帳號作品：", len((report["account"] or {}).get("videos", [])))
```

跑一遍就是上面的示例，6 次呼叫。想拿得更多，把兩個頁數上限調大；帳號作品讀 10 頁是 $0.20。

## 注意事項

- **哪個 ID 用在哪。** 搜尋給的是會過期的 `export/` ID；作品詳情把它換成數字 ID，評論和回覆都要數字 ID。帳號在所有接口裡都是 `v2_…@finder`。
- **哪些是 null。** 搜尋結果沒有評論、轉發、收藏數，也沒有帳號 ID，查詳情才補齊。播放量（`metrics.views`）永遠拿不到，因為影片號本身不公開。隱藏了粉絲數的帳號，`followers` 是 null。每個 null 欄位及原因都寫在 `meta.unavailable` 裡。
- **精簡返回。** `fields=id,text,metrics.likes` 只保留你點名的欄位，`view=compact` 每個物件返回的欄位更少。兩者都不影響價格。
- **回覆。** 評論下面的樓中樓用[影片號評論回覆](https://okdata.online/zh/apis/wechat_channels/comments/replies/list/)，引數是評論 ID 加數字作品 ID。
- **哪些計費。** 已刪除的影片、對不上的帳號返回 `not_found`，請求到了平台就照常計費，平台繁忙和其他平台錯誤也一樣。限流和引數錯誤不扣費。

如果不想寫 Python，想在 Claude 或其他智慧體裡直接調這些介面，接上 [MCP 服務](https://okdata.online/zh/mcp/)即可。拿 key 和試用額度的步驟見[快速開始](https://okdata.online/zh/docs/quickstart/)。

## 示例花費

搜一次“露營裝備”，查排第一的影片詳情，按名稱找一個帳號並拉它最新一頁作品，再讀排第一的影片下兩頁評論

| 介面 | 呼叫次數 | 單價 | 小計 |
|---|---|---|---|
| [影片號影片搜尋](https://okdata.online/zh/apis/wechat_channels/videos/search/) | 1 | $0.02 | $0.02 |
| [影片號作品詳情](https://okdata.online/zh/apis/wechat_channels/videos/get/) | 1 | $0.02 | $0.02 |
| [影片號帳號搜尋](https://okdata.online/zh/apis/wechat_channels/users/search/) | 1 | $0.02 | $0.02 |
| [影片號帳號作品](https://okdata.online/zh/apis/wechat_channels/users/videos/list/) | 1 | $0.02 | $0.02 |
| [影片號作品評論](https://okdata.online/zh/apis/wechat_channels/videos/comments/list/) | 2 | $0.015 | $0.03 |
| 合計 | 6 |  | $0.11 |

按本頁生成時的價格計算。請求到了平台的呼叫，返回為空或出錯也照常計費。

## 在你的 AI 裡用（MCP）

先接好 MCP 服務，然後直接說你要什麼。智慧體會自己找到這些介面、看清價格，再用你的餘額呼叫。

可以這樣說：在影片號搜最近一週的“露營裝備”，開啟最熱的那條，給我它的資料和兩頁評論；再找到帳號“三聯生活週刊”，列出它最新的作品。

```json
{
  "endpoint": "wechat_channels.videos.search",
  "params": {
    "query": "露營裝備推薦"
  },
  "idempotency_key": "<新的 UUID>"
}
```

MCP：`https://api.okdata.online/mcp`

## 本指南用到的介面

- [影片號影片搜尋](https://okdata.online/zh/apis/wechat_channels/videos/search/) `wechat_channels.videos.search`：$0.02/次 · 每頁約 10 條影片
- [影片號作品詳情](https://okdata.online/zh/apis/wechat_channels/videos/get/) `wechat_channels.videos.get`：$0.02/次
- [影片號帳號搜尋](https://okdata.online/zh/apis/wechat_channels/users/search/) `wechat_channels.users.search`：$0.02/次 · 每頁約 1 個帳號
- [影片號帳號作品](https://okdata.online/zh/apis/wechat_channels/users/videos/list/) `wechat_channels.users.videos.list`：$0.02/次 · 每頁約 15 條影片
- [影片號作品評論](https://okdata.online/zh/apis/wechat_channels/videos/comments/list/) `wechat_channels.videos.comments.list`：$0.015/次 · 每頁約 25 條評論

## 更多微信影片號內容

- [微信影片號 API](https://okdata.online/zh/apis/wechat_channels/)
- [怎麼批次匯出影片號影片的評論和回覆](https://okdata.online/zh/guides/wechat-channels-video-comments/)
- [影片號 API Python 教程：搜尋、作品、帳號和評論（2026）](https://okdata.online/zh/guides/wechat-channels-api-python/)
- [怎麼拉取一個影片號帳號釋出的全部影片](https://okdata.online/zh/guides/wechat-channels-user-videos/)
- [抖音、小紅書、影片號的資料有沒有一個 API 能統一拿到？](https://okdata.online/zh/answers/douyin-xiaohongshu-wechat-channels-one-api/)
- [影片號帳號 ID（v2_…@finder）是什麼，為什麼 sph 開頭的影片號 ID 用不了？](https://okdata.online/zh/answers/wechat-channels-finder-id/)
- [怎麼匯出一個影片號博主的全部作品？](https://okdata.online/zh/answers/wechat-channels-export-account-videos/)
- [影片號影片的評論怎麼批次匯出？](https://okdata.online/zh/answers/wechat-channels-export-comments/)
- [影片號影片怎麼按關鍵詞搜尋，拿到播放、點贊和評論數？](https://okdata.online/zh/answers/wechat-channels-video-search-likes-comments/)
- [評論介面](https://okdata.online/zh/roles/posts-comments-list/)
- [帳號作品列表介面](https://okdata.online/zh/roles/accounts-posts-list/)
- [內容詳情介面](https://okdata.online/zh/roles/posts-get/)
- [內容搜尋介面](https://okdata.online/zh/roles/posts-search/)
- [帳號搜尋介面](https://okdata.online/zh/roles/accounts-search/)

## 資料來源

- [微信開放文件：影片號介紹與介面目錄](https://developers.weixin.qq.com/doc/channels/) (讀取於 2026-11-12)
- [微信開放文件：小程式開啟影片號影片](https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/channels-activity.html) (讀取於 2026-11-12)
