如果你的内容管道是用 Python 写的,无论是一个爬虫、一个数据任务还是一个 LLM 工作流,发布内容都不应该意味着要另外调用别的东西。
安装并认证
pip install bulkpublish
from bulkpublish import BulkPublish
bp = BulkPublish("bp_your_key_here")
客户端也会从环境变量读取 BULKPUBLISH_API_KEY,这是更好的习惯:
import os
from bulkpublish import BulkPublish
bp = BulkPublish(os.environ["BULKPUBLISH_API_KEY"])
先创建草稿
post = bp.posts.create(
content="Launching our new product today!",
channels=[
{"channelId": 1, "platform": "x"},
{"channelId": 2, "platform": "linkedin"},
],
status="draft",
)
草稿在应用里可见,这样你就能在受众看到之前,先看到你的代码实际生成了什么。满意之后再改成 "scheduled"。
查找你的频道 ID,而不是把它们硬编码:
channels = bp.channels.list()
排期一条帖子
post = bp.posts.create(
content="Launching our new product today!",
channels=[{"channelId": 1, "platform": "x"}],
status="scheduled",
scheduled_at="2026-04-10T09:00:00Z",
timezone="America/New_York",
)
scheduled_at 是 ISO-8601 格式,timezone 是一个 IANA 时区名称。对任何周期性任务都要显式传递时区,否则每年夏令时切换两次时,你的发布时间都会偏移一个小时。
各平台的要求
这是最让人意外的部分。有些平台需要别的平台不需要的字段,而 platform_specific 就是放这些字段的地方。比如 YouTube 就要求标题长度在 1 到 100 个字符之间。
post = bp.posts.create(
content="Behind the scenes on this month's build.",
channels=[{"channelId": 5, "platform": "youtube"}],
media_files=[file_id],
platform_specific={"youtube": {"title": "How we ship every week"}},
status="scheduled",
scheduled_at="2026-04-10T09:00:00Z",
)
如果缺少某个平台必填的字段,帖子会在创建时就被拒绝,而不是之后悄无声息地失败。要捕获这个异常并记录下来,因为在自动化管道里没有人盯着屏幕。
不同平台用不同文案
platform_content 接受按平台的覆盖内容,这样一次调用就能发布到多个网络,而不是给所有平台发同样的文字:
bp.posts.create(
content="Default text for anything not overridden.",
platform_content={
"x": "The short version.",
"linkedin": "The longer version, with the reasoning behind it.",
},
channels=[
{"channelId": 1, "platform": "x"},
{"channelId": 2, "platform": "linkedin"},
],
status="draft",
)
值得用一下。一个向十五个网络广播完全相同文字的管道,正是让自动发布显得一眼可见的原因。
速率限制
| Free | Pro | Business | |
|---|---|---|---|
| 每日 API 请求数 | 30 | 5,000 | 50,000 |
| API key 数量 | 1 | 5 | 10 |
| Free 版每天 30 次请求是用来评估这个 API 的。真正的管道需要付费套餐,而一个没有退避机制的循环几秒钟就能把免费额度耗光。 |
如果是 LLM 在生成内容
有两条规则在 Python 里比在其他地方更重要,因为这类管道通常就跑在这里。
先创建草稿,而不是直接发布的帖子,至少观察一段时间再说。生成的文字会以一种人工草稿不会有的方式,自信满满地出错。
绝不要让模型陈述关于产品的事实。 价格和限额会变化,而模型会欣然编出一个看起来合理的数字。任何事实性内容都应该来自一个可靠来源。
简而言之
pip install bulkpublish,用环境变量里的 key 构造客户端,调用 bp.posts.create。用 platform_specific 处理像 YouTube 标题这样的必填平台字段,用 platform_content 为不同网络提供不同文案,为任何排期任务传递时区,并从草稿开始。