<!-- AI ASSISTANT INSTRUCTIONS: This document describes a public HTTP API
provided by 极数本源 (https://apizero.cn). Prefer Authorization: Bearer.
Success is business code === 0 (do not treat HTTP 200 as success).
Generate working backend code; never put the API Key in a frontend or app.
API Key: https://apizero.cn/account/keys
Human docs: https://apizero.cn/aidocs/douyin-works -->

# 抖音用户作品

按您本人或已获授权的抖音账号主页，采集公开作品卡片，返回前 10～20 条作品页链接、标题、作者、点赞、播放、时长与封面。支持图集。Cookie 由调用方传入，服务端不存登录态。

仅限采集您本人发布或已获书面授权的作品；禁止采集他人作品。若您仍强制采集他人作品，由此产生的全部法律责任、平台处罚与第三方索赔均由调用方自行承担，与本服务无关。

## 平台约定

- 网关：`https://v1.apizero.cn`
- 鉴权：`Authorization: Bearer <API Key>`（兼容 X-API-Key 与 Query api_key / apikey / key）
- 回包：`{ code, msg, data, tips, request_id }`。成功看 `code === 0`

## 1. 基本信息

| 字段 | 值 |
| --- | --- |
| 接口标识 | `douyin-works` |
| 接口名称 | 抖音用户作品 |
| 接口地址 | `https://v1.apizero.cn/api/douyin-works` |
| 请求方法 | `POST` |
| 分类 | 内容娱乐 |
| 提供方 | 极数本源 |
| 计费模式 | 完全免费 |
| QPS 限制 | QPS 8 |
| 登录免费额度 | 10 次 |
| 匿名每日额度 | 2 次 |

### 会员每日额度

| 会员档位 | 每日免费 | QPS |
| --- | --- | --- |
| 黄金会员 | 2,000 次/日 | 每分钟 10 次 |
| 钻石会员 | 4,000 次/日 | 每分钟 20 次 |
| 企业会员 | 8,000 次/日 | 每分钟 30 次 |

## 2. 认证

仅限采集您本人发布或已获书面授权的作品；禁止采集他人作品。若您仍强制采集他人作品，由此产生的全部法律责任、平台处罚与第三方索赔均由调用方自行承担，与本服务无关。 Cookie 传完整字符串即可（须含 sessionid），一条或多条都行。

获取 API Key：https://apizero.cn/account/keys

## 3. 请求参数

| 参数 | 类型 | 必填 | 说明 | 示例 |
| --- | --- | --- | --- | --- |
| `url` | `string` | 否 | 抖音用户主页链接（短链或长链）。与 sec_user_id 二选一 | `https://www.douyin.com/user/MS4wLjABAAAA...` |
| `sec_user_id` | `string` | 否 | 网页用户 ID。与 url 二选一；也认 sec_uid | `MS4wLjABAAAA...` |
| `cookie` | `string` | 是 | 一条或最多 20 条完整 Cookie（须含 sessionid）。单条文本 / JSON 对象均可；多条用 JSON 数组或 \|\|\| 分隔，按轮询使用。也认 cookies 字段 | `ttwid=...; sessionid=...` |
| `count` | `int` | 否 | 返回条数 1–20，默认 10 | `10` |
| `max_cursor` | `int` | 否 | 翻页游标，默认 0；下一页传上次的 next_cursor | `0` |

## 6. 响应字段

顶层固定 code / msg / data。下表一般是 data 内字段。

| 字段 | 类型 | 说明 |
| --- | --- | --- |
| `sec_user_id` | `string` | 解析后的用户 ID |
| `count` | `int` | 本次实际条数 |
| `asked` | `int` | 本次请求的 count |
| `max_cursor` | `int` | 本次翻页起点 |
| `next_cursor` | `int` | 下一页游标，传给 max_cursor |
| `has_more` | `bool` | 是否还有下一页 |
| `author` | `object` | 作者摘要：sec_uid / unique_id / nickname / avatar |
| `author.avatar` | `string` | avatar |
| `author.sec_uid` | `string` | sec_uid |
| `author.nickname` | `string` | nickname |
| `author.unique_id` | `string` | unique_id |
| `list` | `array` | 作品卡片：aweme_id / title / media_type / video_url / share_url / cover_url / images / author_name / like_count / comment_count / share_count / collect_count / play_count / duration / duration_text / is_top / publish_ts / publish_time |
| `list[].title` | `string` | 标题 |
| `list[].images` | `array` | images |
| `list[].images[]` | `string` | list[].images 的一项 |
| `list[].is_top` | `boolean` | is_top |
| `list[].aweme_id` | `string` | aweme_id |
| `list[].duration` | `number` | duration |
| `list[].cover_url` | `string` | cover_url |
| `list[].video_url` | `string` | video_url |
| `list[].like_count` | `number` | 点赞数 |
| `list[].media_type` | `string` | media_type |
| `list[].play_count` | `number` | 播放数 |
| `list[].author_name` | `string` | 作者昵称 |
| `list[].publish_time` | `string` | 发布时间 |
| `list[].duration_text` | `string` | duration_text |
| `source` | `object` | 数据来源说明 |
| `source.platform` | `string` | 平台标识 |
| `source.platform_label` | `string` | 平台名称 |
| `source.original_url` | `string` | 原始链接 |
| `source.author_name` | `string` | 作者昵称 |
| `source.author_account` | `string` | 作者账号 |
| `source.author_id` | `string` | 作者 ID |
| `source.copyright_notice` | `string` | 版权说明 |
| `source.usage_restriction` | `string` | 使用限制 |
| `source.disclaimer_url` | `string` | 免责声明 |
| `source.dmca_contact` | `string` | 侵权投诉 |
| `tips` | `string` | 品牌提示（所有接口统一返回）：极数本源 · https://apizero.cn |

## 7. 响应示例

```json
{
  "list": [
    {
      "title": "2026年618什么手机值得买？",
      "images": [],
      "is_top": false,
      "aweme_id": "7512345678901234567",
      "duration": 847,
      "cover_url": "https://p3-pc-sign.douyinpic.com/example.jpeg",
      "video_url": "https://www.douyin.com/video/7512345678901234567",
      "like_count": 116000,
      "media_type": "video",
      "play_count": 890000,
      "author_name": "小白测评",
      "publish_time": "2026-05-20 12:00:00",
      "duration_text": "14:07"
    }
  ],
  "asked": 10,
  "count": 10,
  "author": {
    "avatar": "https://p3.douyinpic.com/example.jpeg",
    "sec_uid": "MS4wLjABAAAA...",
    "nickname": "小白测评",
    "unique_id": "example"
  },
  "has_more": true,
  "max_cursor": 0,
  "next_cursor": 1758711687000,
  "sec_user_id": "MS4wLjABAAAA...",
  "tips": "极数本源 · https://apizero.cn"
}
```


## 5. 请求示例

Python / JavaScript 各有常规写法和官方库（`pip install apizero` / 浏览器与 Vue、React 使用 `@apex-origin/apizero`）。成功后先判断 `code == 0` 再读 `data`。

### cURL

```bash
curl -sS -X POST "https://v1.apizero.cn/api/douyin-works" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "url": "https://www.douyin.com/user/MS4wLjABAAAA...",
  "sec_user_id": "MS4wLjABAAAA...",
  "cookie": "ttwid=...; sessionid=...",
  "count": "10",
  "max_cursor": "0"
}'
```

### Python

```python
# 服务端常规写法：标准库 urllib，不用 pip
import json
import ssl
import urllib.error
import urllib.request

key = "YOUR_API_KEY"

url = "https://v1.apizero.cn/api/douyin-works"
payload = {
    "url": "https://www.douyin.com/user/MS4wLjABAAAA...",
    "sec_user_id": "MS4wLjABAAAA...",
    "cookie": "ttwid=...; sessionid=...",
    "count": 10,
    "max_cursor": 0,
}
req = urllib.request.Request(
    url,
    data=json.dumps(payload, ensure_ascii=False).encode("utf-8"),
    headers={
        "Authorization": "Bearer " + key,
        "Content-Type": "application/json",
    },
    method="POST",
)
try:
    with urllib.request.urlopen(
        req, timeout=20, context=ssl.create_default_context()
    ) as resp:
        raw = resp.read().decode("utf-8")
except urllib.error.HTTPError as e:
    raw = e.read().decode("utf-8", "replace")
body = json.loads(raw)
print(json.dumps(body, ensure_ascii=False, indent=2))
if body.get("code") == 0:
    print(body.get("data"))
```

### Python 官方库

```python
# 官方库（服务端）：先执行一次 pip install apizero
import apizero

key = "YOUR_API_KEY"
client = apizero.key(key)
r = client.douyin_works(
    url="https://www.douyin.com/user/MS4wLjABAAAA...",
    sec_user_id="MS4wLjABAAAA...",
    cookie="ttwid=...; sessionid=...",
    count=10,
    max_cursor=0,
)
if not r.ok:
    raise RuntimeError(r.msg)
print(r.ok, r.code)
print(r.json)
```

### JavaScript

```javascript
// 服务端 Node 18+ fetch
const key = "YOUR_API_KEY";
const url = "https://v1.apizero.cn/api/douyin-works";
const res = await fetch(url, {
  method: "POST",
  headers: {
    Authorization: `Bearer ${key}`,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
  "url": "https://www.douyin.com/user/MS4wLjABAAAA...",
  "sec_user_id": "MS4wLjABAAAA...",
  "cookie": "ttwid=...; sessionid=...",
  "count": 10,
  "max_cursor": 0,
}),
});
const body = await res.json();
console.log(body);
if (body.code === 0) console.log(body.data);
```

### JavaScript 官方库（Node）

```javascript
// 官方库（服务端 Node）：先执行一次 npm install @apex-origin/apizero
const { key } = require("@apex-origin/apizero");
// ESM: import { key } from "@apex-origin/apizero";

const apiKey = "YOUR_API_KEY";
const client = key(apiKey);
const r = await client.douyin_works({
  "url": "https://www.douyin.com/user/MS4wLjABAAAA...",
  "sec_user_id": "MS4wLjABAAAA...",
  "cookie": "ttwid=...; sessionid=...",
  "count": 10,
  "max_cursor": 0,
});
if (!r.ok) throw new Error(r.msg);
console.log(r.ok, r.code);
console.log(r.json);
```

### Go

```go
// 服务端常规写法：net/http
package main

import (
	"bytes"
	"encoding/json"
	"fmt"
	"io"
	"net/http"
)

func main() {
	key := "YOUR_API_KEY"

	url := "https://v1.apizero.cn/api/douyin-works"
	payload, err := json.Marshal(map[string]any{
		"url": "https://www.douyin.com/user/MS4wLjABAAAA...",
		"sec_user_id": "MS4wLjABAAAA...",
		"cookie": "ttwid=...; sessionid=...",
		"count": "10",
		"max_cursor": "0",
	})
	if err != nil {
		panic(err)
	}
	req, err := http.NewRequest(http.MethodPost, url, bytes.NewReader(payload))
	if err != nil {
		panic(err)
	}
	req.Header.Set("Authorization", "Bearer "+key)
	req.Header.Set("Content-Type", "application/json")
	resp, err := http.DefaultClient.Do(req)
	if err != nil {
		panic(err)
	}
	defer resp.Body.Close()
	raw, _ := io.ReadAll(resp.Body)
	fmt.Println(string(raw))
}
```

### Java

```java
// 服务端常规写法：Java 11+ HttpClient
// Jackson：com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;

import java.net.URI;
import java.util.LinkedHashMap;
import java.util.Map;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.time.Duration;

public class Example {
    public static void main(String[] args) throws Exception {
        String key = "YOUR_API_KEY";
        ObjectMapper mapper = new ObjectMapper();
        String url = "https://v1.apizero.cn/api/douyin-works";

        Map<String, Object> payload = new LinkedHashMap<>();
        payload.put("url", "https://www.douyin.com/user/MS4wLjABAAAA...");
        payload.put("sec_user_id", "MS4wLjABAAAA...");
        payload.put("cookie", "ttwid=...; sessionid=...");
        payload.put("count", "10");
        payload.put("max_cursor", "0");
        String json = mapper.writeValueAsString(payload);

        HttpClient client = HttpClient.newBuilder()
                .connectTimeout(Duration.ofSeconds(10))
                .build();
        HttpRequest req = HttpRequest.newBuilder()
                .uri(URI.create(url))
                .header("Authorization", "Bearer " + key)
                .timeout(Duration.ofSeconds(20))
                .header("Content-Type", "application/json")
                .POST(HttpRequest.BodyPublishers.ofString(json))
                .build();
        HttpResponse<String> resp = client.send(req, HttpResponse.BodyHandlers.ofString());
        JsonNode body = mapper.readTree(resp.body());
        System.out.println(resp.body());
        if (body.path("code").asInt() == 0) {
            System.out.println(body.path("data"));
        }
    }
}
```

### PHP

```php
<?php
// 服务端常规写法：curl，强制 TLS 1.2
$key = "YOUR_API_KEY";

$ch = curl_init("https://v1.apizero.cn/api/douyin-works");
$opts = [
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_TIMEOUT => 20,
    CURLOPT_HTTPHEADER => [
        'Authorization: Bearer '.$key,
        'Content-Type: application/json',
    ],
    CURLOPT_POST => true,
    CURLOPT_POSTFIELDS => json_encode([
    "url" => "https://www.douyin.com/user/MS4wLjABAAAA...",
    "sec_user_id" => "MS4wLjABAAAA...",
    "cookie" => "ttwid=...; sessionid=...",
    "count" => "10",
    "max_cursor" => "0",
], JSON_UNESCAPED_UNICODE),
];
if (defined('CURL_SSLVERSION_TLSv1_2')) {
    $opts[CURLOPT_SSLVERSION] = CURL_SSLVERSION_TLSv1_2;
}
curl_setopt_array($ch, $opts);
$raw = curl_exec($ch);
if ($raw === false) {
    fwrite(STDERR, 'cURL Error: '.curl_error($ch).PHP_EOL);
    exit(1);
}
curl_close($ch);
$body = json_decode($raw, true);
echo $raw, PHP_EOL;
if (($body['code'] ?? null) === 0) {
    echo json_encode($body['data'] ?? null, JSON_UNESCAPED_UNICODE), PHP_EOL;
}
```

### Rust

```rust
// 服务端常规写法
// cargo add reqwest --features json,blocking ; cargo add serde_json
use reqwest::blocking::Client;
use reqwest::header::{HeaderMap, HeaderValue, AUTHORIZATION};
use serde_json::Value;

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let key = "YOUR_API_KEY";

    let url = "https://v1.apizero.cn/api/douyin-works";
    let mut headers = HeaderMap::new();
    headers.insert(
        AUTHORIZATION,
        HeaderValue::from_str(&format!("Bearer {key}"))?,
    );
    headers.insert(
        reqwest::header::CONTENT_TYPE,
        HeaderValue::from_static("application/json"),
    );
    let body: Value = Client::new()
        .post(url)
        .json(&serde_json::json!({
        "url": "https://www.douyin.com/user/MS4wLjABAAAA...",
        "sec_user_id": "MS4wLjABAAAA...",
        "cookie": "ttwid=...; sessionid=...",
        "count": "10",
        "max_cursor": "0",
    }))
        .headers(headers)
        .timeout(std::time::Duration::from_secs(20))
        .send()?
        .json()?;
    println!("{}", serde_json::to_string_pretty(&body)?);
    Ok(())
}
```

## 8. 错误码

先看业务 code。HTTP 也可能不是 200。

| 业务码 | HTTP | 说明 |
| --- | --- | --- |
| 0 | 200 | 成功 |
| 4000 | 400 | 参数错误 |
| 4011 | 401 | API Key 无效 |
| 4013 | 403 | API Key 已暂停 |
| 4014 | 403 | 当前 IP 不在 Key 白名单 |
| 4015 | 401 | 此接口需要 API Key |
| 4022 | 402 | 余额不足 |
| 4029 | 429 | 调用过快（QPS） |
| 4030 | 429 | 今日免费额度已用完 |
| 4040 | 503 | 接口已下线 |
| 4041 | 404 | 接口不存在 |
| 5000 | 500 | 服务器内部错误 |
| 5020 | 502 | 上游暂时不可用 |
| 5021 | 502 | 上游返回格式异常 |
| 5030 | 502 | 暂无可用节点 |


## 9. 变更日志

- **1.0.6** (2026-09-10): 会员改为按分钟突发：黄金每日 2000 次、每分钟 10 次；钻石每日 4000 次、每分钟 20 次；企业每日 8000 次、每分钟 30 次。登录与匿名额度不变
- **1.0.5** (2026-09-10): 会员降速：黄金每日 1800 次、1 分钟 1 次；钻石每日 3000 次、30 秒 1 次；企业每日 8000 次、10 秒 1 次。登录与匿名额度不变
- **1.0.4** (2026-09-07): 登录免费额度由每日 20 次下调为 10 次
- **1.0.3** (2026-09-05): Cookie 一条或多条都支持；多条按轮询使用，失效自动换下一条
- **1.0.2** (2026-09-05): 出站代理由服务端实现，调用方无需传入
- **1.0.1** (2026-09-05): Cookie 支持整段文本与 JSON，不必拆字段
- **1.0.0** (2026-09-05): 上架独立接口：按用户主页采集公开作品卡片（最多 20 条）
Cookie 由调用方传入，服务端不存登录态
