登录开始免费试用
easyCoexistence 官方 API

如何通过 API 向 TikTok 发布视频

要通过 TikTok 的 API for Business 发布视频,请向 POST /business/video/publish/ 发送请求,内含账户的 business_id、位于已验证域名或 URL 前缀下的 video_url,以及包含文案和设置的 post_info 对象,并附带 Access-Token 请求头。TikTok 会返回 share_id;将其作为 publish_id 传给 /business/publish/status/,直到状态显示 PUBLISH_COMPLETE 且出现 post_ids。

easyCoexistence 可通过 publish_tiktok_post 从 Claude、ChatGPT 或你自己的智能体发布 TikTok 视频:提供 HTTPS 链接、文案以及评论是否开启,然后用 get_tiktok_publish_status 跟踪帖子,文件则经由其已验证的媒体路由传送至 TikTok。

share_id

发布调用返回的值,形如 v_pub_url~v1.2345123456789123456,并作为 publish_id 传给状态查询调用。

Nov 16, 2023

自此起,TikTok 会拒绝发布来自未验证域名或 URL 前缀的视频。

6 a minute

TikTok 对每个账户通过发布端点发布视频设定了上限,每天最多 15 条。

3 min

PUBLISH_COMPLETE 之后 post_ids 出现所需的时间;TikTok 建议三分钟后重试。

post_id

视频通过审核后,会在 post.publish.publicly_available Webhook 中发送,可用于查询其数据洞察。

首次调用前需要准备什么?

三样东西。一是 TikTok 账户的访问令牌,以及从令牌交换中获得的账户 open_id;二是在 TikTok Accounts 下拥有 Video Publish 权限的开发者应用;三是位于公开 HTTPS 或 HTTP URL 上的视频,且该 URL 位于已为该应用验证的域名或 URL 前缀之下。TikTok 会自行下载文件,因此该链接必须保持可访问,TikTok 建议 URL 至少有效 30 分钟。

发布请求是什么样的?

向 https://business-api.tiktok.com/open_api/v1.3/business/video/publish/ 发送 POST 请求,账户的令牌放在 Access-Token 请求头中,并将 Content-Type 设为 application/json。JSON 请求体中,business_id 指定账户,video_url 指定文件,post_info 指定发布设置。下例发布一条带文案的视频,评论、Duet 和 Stitch 均保持开启:

Publish a video with curl
curl -X POST 'https://business-api.tiktok.com/open_api/v1.3/business/video/publish/' \
  -H 'Access-Token: <ACCESS_TOKEN>' \
  -H 'Content-Type: application/json' \
  -d '{
    "business_id": "<OPEN_ID>",
    "video_url": "https://media.example.com/tiktok/launch.mp4",
    "post_info": {
      "caption": "Our new menu is live #food",
      "is_brand_organic": false,
      "is_branded_content": false,
      "disable_comment": false,
      "disable_duet": false,
      "disable_stitch": false
    }
  }'

每个请求体字段的作用是什么?

以下字段来自 TikTok 参考文档中视频发布的列表,按顶层到嵌套顺序排列。封面、AI 生成标签、位置、草稿以及仅限广告的选项也位于同一请求体中:

  • business_id:来自令牌交换的账户 open_id。
  • video_url:TikTok 下载的文件,格式为 MP4、MOV 或 WebM,位于已验证的域名或 URL 前缀之下。
  • post_info:每次调用都必需,即使只是空对象,它也是发布设置的所在处。
  • post_info.caption:最多 2,200 个字符(按 UTF-16 计算),可包含 #话题标签和最多 30 个 @提及。
  • post_info.is_brand_organic 和 is_branded_content:对应“推广内容”和“付费合作”标签,TikTok 的表格将其标为必填。
  • post_info.disable_comment、disable_duet 和 disable_stitch:设为 true 时分别关闭评论、Duet 或 Stitch;三者默认均为 false。

TikTok 返回什么?

常规响应结构,其中 data 包含发布任务的 ID。code 为 0 表示 TikTok 已接受该任务,但并不意味着视频已上线:TikTok 仍需下载文件、检查并审核帖子。在 TikTok 的示例中,视频的 share_id 以 v_pub_url 开头,图片帖子的则以 p_pub_url 开头。

The publish response
{
  "code": 0,
  "message": "Ok",
  "request_id": "20210817034316010245031056097316BA",
  "data": {
    "share_id": "v_pub_url~v1.2345123456789123456"
  }
}

如何跟踪帖子直至上线?

使用 GET /business/publish/status/,并将 business_id 和 share_id 作为 publish_id 传入。TikTok 下载文件时,status 显示 PROCESSING_DOWNLOAD;帖子通过审核后显示 PUBLISH_COMPLETE;失败时显示 FAILED 并附原因。帖子可公开查看时,post_ids 会随 PUBLISH_COMPLETE 一同返回,且可能最多延迟三分钟。以下是完整的 Python 流程:

Publish and follow a video in Python
import os, time, requests

API = "https://business-api.tiktok.com/open_api/v1.3"
HEADERS = {"Access-Token": os.environ["TIKTOK_ACCESS_TOKEN"]}
BUSINESS_ID = os.environ["TIKTOK_BUSINESS_ID"]  # open_id from the token exchange

def call(method, path, **kwargs):
    body = requests.request(method, f"{API}/{path}", headers=HEADERS, timeout=30, **kwargs).json()
    if body.get("code") != 0:  # errors arrive in code, usually with HTTP 200
        raise RuntimeError(f"{body.get('code')}: {body.get('message')}")
    return body["data"]

share_id = call("POST", "business/video/publish/", json={
    "business_id": BUSINESS_ID,
    "video_url": "https://media.example.com/tiktok/launch.mp4",
    "post_info": {"caption": "Our new menu is live #food",
                  "is_brand_organic": False, "is_branded_content": False},
})["share_id"]

for _ in range(30):
    time.sleep(60)  # each check is a call; TikTok's stages take minutes
    s = call("GET", "business/publish/status/",
             params={"business_id": BUSINESS_ID, "publish_id": share_id})
    if s["status"] == "FAILED":
        raise RuntimeError(s.get("reason"))
    if s["status"] == "PUBLISH_COMPLETE" and s.get("post_ids"):
        print("Live:", s["post_ids"])
        break

Webhook 能否取代状态查询?

可以,适用于通过 /business/webhook/update/ 订阅 event_type VIDEO 事件的应用。TikTok 下载并检查文件后,会推送 post.publish.failed 或 post.publish.complete;审核通过后,会推送带有新 post_id 的 post.publish.publicly_available;若帖子之后不再公开可见,则推送 post.publish.no_longer_publicly_available。每个事件都会在 publish_id 中注明任务,其值与 share_id 相同。

如何通过 MCP 发布视频?

在 Claude、ChatGPT 或其他连接到 https://easycoexistence.com/api/mcp 的客户端中,用平常的话提出请求即可。助手会调用 publish_tiktok_post,传入来自 list_social_accounts 的 account_id、HTTPS 格式的 video_url 和文案;若希望关闭评论,则再传入 disable_comment。结果会返回 TikTok 的 share_id;随后,把 account_id 和该 share_id 交给 get_tiktok_publish_status,即可原样返回 TikTok 的状态、post_ids 和原因。

The MCP tool calls and their results
publish_tiktok_post {
  "account_id": "<ACCOUNT_ID>",
  "video_url": "https://media.example.com/tiktok/launch.mp4",
  "caption": "Our new menu is live #food",
  "disable_comment": false
}
=> { "share_id": "v_pub_url~v1.2345123456789123456",
     "note": "TikTok is processing the post. Check it with get_tiktok_publish_status." }

get_tiktok_publish_status { "account_id": "<ACCOUNT_ID>", "share_id": "v_pub_url~v1.2345123456789123456" }
=> { "status": "PUBLISH_COMPLETE", "post_ids": ["<POST_ID>"] }

publish_tiktok_post 向 TikTok 发送什么?

向同一端点发起调用,内容由你的请求填充。你的链接会以签名链接的形式,经由 easyCoexistence 自有的已验证媒体路由发送给 TikTok,因此无需单独验证;文案和 disable_comment 按你所给的原样发送;is_brand_organic 和 is_branded_content 则以 false 发送。Duet、Stitch、封面和 AI 生成标签等其他设置保持 TikTok 的默认值,视频按端点的设计以公开帖子形式发布。

使用 Partner API 的凭证能做什么?

可以直接以该账户身份调用 TikTok。在 https://easycoexistence.com/api/v1 上发送 GET /channels/{id}?credentials=1,并以你的 ec_live_ 密钥作为 Bearer 令牌,即可返回该渠道及其 credentials 对象,其中包含 api_base、business_id、当前的 access_token 和 token_expires_at。之后,状态查询、视频列表、评论和数据洞察都可由你自己的代码执行。需要提前规划的是发布部分:直接发布调用会原样将 video_url 传给 TikTok;URL 属性需要使用开发者应用自身的 ID 和密钥添加;而 easyCoexistence 应用已验证的前缀即为其媒体路由,publish_tiktok_post 正是使用该路由。

Credentials from the Partner API, then a direct status check
curl "https://easycoexistence.com/api/v1/channels/$CHANNEL_ID?credentials=1" \
  -H "Authorization: Bearer $EC_API_KEY"

# "credentials": {
#   "platform": "tiktok",
#   "api_base": "https://business-api.tiktok.com/open_api/v1.3",
#   "business_id": "<OPEN_ID>",
#   "access_token": "<ACCESS_TOKEN>",
#   "token_expires_at": "2026-11-01T09:00:00.000Z", ...
# }

curl -G 'https://business-api.tiktok.com/open_api/v1.3/business/publish/status/' \
  -H 'Access-Token: <ACCESS_TOKEN>' \
  --data-urlencode 'business_id=<OPEN_ID>' \
  --data-urlencode 'publish_id=<SHARE_ID>'

设置方法

  1. Get the token and the account IDExchange the owner's authorization code at /tt_user/oauth2/token/, and keep access_token for the header and open_id for business_id.
  2. Host the videoPut the MP4, MOV or WebM file under a domain or URL prefix verified for your app, where it stays reachable for at least 30 minutes.
  3. Call the publish endpointPOST business_id, video_url and post_info, with the caption, the two brand flags and the engagement switches, to /business/video/publish/.
  4. Keep the share_idStore data.share_id from the response, the ID of this publishing task.
  5. Check the statusEvery few minutes, GET /business/publish/status/ with business_id and the share_id as publish_id, until PUBLISH_COMPLETE or FAILED.
  6. Record the post IDTake it from post_ids, or from post_id in the post.publish.publicly_available webhook, to read the video's metrics later.

常见错误

  • 忘记 post_info。即使没有修改任何设置,TikTok 也要求每次调用都包含该对象。
  • 在发布响应中寻找帖子 ID。响应仅返回 share_id;post_ids 需从状态查询或 post.publish.publicly_available Webhook 中获取。
  • 重复调用超时的发布请求。第一次请求可能已到达 TikTok,因此再次发送前,请先检查该账户的最新帖子。
  • 将代码 0 视为视频已上线。它仅表示 TikTok 已接受任务,文件在下载后仍可能未通过检查。
使用 EasyCoexistence 完成这些操作

每个连接每月 US$ 9 起,连接越多越便宜,最低降至 US$ 0.75;并含前 3 天免费试用。

常见问题

哪个端点可以向 TikTok 发布视频?

POST https://business-api.tiktok.com/open_api/v1.3/business/video/publish/,账户令牌放在 Access-Token 请求头中,JSON 请求体包含 business_id、video_url 和 post_info。

TikTok API 能否直接上传视频文件?

不能通过 /business/video/publish/ 直接上传。该接口接收 video_url,并从该地址获取文件,因此视频需要位于已验证域名或 URL 前缀下的 URL 中。

如何获取通过 API 发布的视频 ID?

可从 /business/publish/status/ 返回的 post_ids 获取(状态为 PUBLISH_COMPLETE 且帖子已公开后),或从 post.publish.publicly_available Webhook 中的 post_id 获取。

能否通过 API 为 TikTok 视频设置定时发布?

发布端点在调用时即刻发布,没有时间字段。easyCoexistence 会将定时帖子保存在自己的队列中,并在你设定的时间调用 TikTok。

继续阅读

两分钟连接您的第一个渠道。

无需等待平台审核。连接 WhatsApp、Instagram、TikTok 或其他渠道,然后让您的 AI 发布、回复或生成报告,看它如何运作。

  • 免费试用 3 天
  • 随时取消
  • 仅使用官方 API
  • 全天候 24/7 监控

验证时间