devto
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseCall the Forem API v1 (dev.to) with . The user's API key is in
; every call needs the headers and
. Base URL: .
curl + jq$DEVTO_API_KEYapi-key: $DEVTO_API_KEYAccept: application/vnd.forem.api-v1+jsonhttps://dev.to/apiErrors come back as JSON with an / field — show them verbatim.
means the API key is invalid → the user must re-connect the DEV connector.
errorstatus401Always start by confirming the key and learning the account:
bash
curl -sS -H "api-key: $DEVTO_API_KEY" -H "Accept: application/vnd.forem.api-v1+json" \
"https://dev.to/api/users/me" | jq '{username, name}'使用调用Forem API v1(dev.to)。用户的API密钥存储在中;每次调用都需要携带请求头和。基础URL为:。
curl + jq$DEVTO_API_KEYapi-key: $DEVTO_API_KEYAccept: application/vnd.forem.api-v1+jsonhttps://dev.to/api错误信息会以JSON格式返回,包含/字段——请直接展示这些信息。表示API密钥无效→用户必须重新连接DEV连接器。
errorstatus401请始终先确认密钥有效性并获取账户信息:
bash
curl -sS -H "api-key: $DEVTO_API_KEY" -H "Accept: application/vnd.forem.api-v1+json" \
"https://dev.to/api/users/me" | jq '{username, name}'Publish an article
发布文章
Confirm with the user before publishing publicly. Default to a draft
() unless they explicitly say publish/now.
published:falsebash
TITLE="My title"
BODY_MD="$(cat article.md)" # full Markdown body
jq -n --arg t "$TITLE" --arg b "$BODY_MD" \
'{article:{title:$t, body_markdown:$b, published:false, tags:["ai","webdev"]}}' \
| curl -sS -X POST "https://dev.to/api/articles" \
-H "api-key: $DEVTO_API_KEY" \
-H "Accept: application/vnd.forem.api-v1+json" \
-H "Content-Type: application/json" \
-d @- \
| jq '{id, url, published}'To publish a draft later (or edit), with the same
shape (set ). Front-matter inside (a
block) can also carry , , , , .
PUT /api/articles/{id}published:truebody_markdown---titletagsseriescanonical_urlcover_image- Canonical URL: when cross-posting, set
so DEV points SEO back to the source — important for the article→video / cross-publishing flow.
"canonical_url":"https://your-blog/original"
公开发布前请与用户确认。 默认设置为草稿(),除非用户明确要求立即发布。
published:falsebash
TITLE="My title"
BODY_MD="$(cat article.md)" # full Markdown body
jq -n --arg t "$TITLE" --arg b "$BODY_MD" \
'{article:{title:$t, body_markdown:$b, published:false, tags:["ai","webdev"]}}' \
| curl -sS -X POST "https://dev.to/api/articles" \
-H "api-key: $DEVTO_API_KEY" \
-H "Accept: application/vnd.forem.api-v1+json" \
-H "Content-Type: application/json" \
-d @- \
| jq '{id, url, published}'如需稍后发布草稿(或编辑文章),请使用接口,请求体格式保持一致(设置)。中的前置内容块(包裹的部分)也可以包含、、、、等字段。
PUT /api/articles/{id}published:truebody_markdown---titletagsseriescanonical_urlcover_image- 规范URL(Canonical URL): 交叉发布时,请设置,这样DEV会将SEO权重指向原文章来源——这在文章转视频/交叉发布流程中非常重要。
"canonical_url":"https://your-blog/original"
List / inspect my articles
列出/查看我的文章
bash
undefinedbash
undefinedMy published + draft articles (paginated; per_page max 1000).
我的已发布+草稿文章(分页;per_page最大值为1000)。
curl -sS -H "api-key: $DEVTO_API_KEY" -H "Accept: application/vnd.forem.api-v1+json"
"https://dev.to/api/articles/me/all?per_page=30"
| jq '.[] | {id, title, published, page_views_count, public_reactions_count, comments_count}'
"https://dev.to/api/articles/me/all?per_page=30"
| jq '.[] | {id, title, published, page_views_count, public_reactions_count, comments_count}'
curl -sS -H "api-key: $DEVTO_API_KEY" -H "Accept: application/vnd.forem.api-v1+json"
"https://dev.to/api/articles/me/all?per_page=30"
| jq '.[] | {id, title, published, page_views_count, public_reactions_count, comments_count}'
"https://dev.to/api/articles/me/all?per_page=30"
| jq '.[] | {id, title, published, page_views_count, public_reactions_count, comments_count}'
A single article's full content + stats.
单篇文章的完整内容+统计数据。
curl -sS -H "api-key: $DEVTO_API_KEY" -H "Accept: application/vnd.forem.api-v1+json"
"https://dev.to/api/articles/ARTICLE_ID" | jq '{title, url, reactions: .public_reactions_count, views: .page_views_count}'
"https://dev.to/api/articles/ARTICLE_ID" | jq '{title, url, reactions: .public_reactions_count, views: .page_views_count}'
undefinedcurl -sS -H "api-key: $DEVTO_API_KEY" -H "Accept: application/vnd.forem.api-v1+json"
"https://dev.to/api/articles/ARTICLE_ID" | jq '{title, url, reactions: .public_reactions_count, views: .page_views_count}'
"https://dev.to/api/articles/ARTICLE_ID" | jq '{title, url, reactions: .public_reactions_count, views: .page_views_count}'
undefinedGotchas
注意事项
- Tags: max 4, lowercase, no spaces (e.g. ,
webdev).machinelearning - Rate limit: article create/update is throttled (a few per 30s); space out
bulk publishes or you'll get .
429 - is the source of truth — if you put a
body_markdownfront-matter block at the top, its fields override the JSON---fields.article
- 标签: 最多4个,小写,无空格(例如、
webdev)。machinelearning - 速率限制: 文章创建/更新操作有节流限制(每30秒最多几次);批量发布时请间隔一段时间,否则会收到错误。
429 - 是信息的唯一来源——如果在顶部添加
body_markdown前置内容块,其中的字段会覆盖JSON中---的对应字段。article
Record the output
记录输出结果
After you successfully publish and obtain the live result URL, call the built-in
tool ONCE so the user can track this deliverable in My Outputs:
publish_artifactpublish_artifact(kind="article", channel="devto", title="<title>", url="<the REAL returned URL>", status="delivered")Use the real returned URL — never fabricate one. Call it once per published item,
only after delivery is confirmed; skip it (or use ) if publishing failed.
See .
status="failed"_shared/artifacts.md成功发布并获取到实际结果URL后,请调用内置的工具一次,以便用户在「我的输出」中跟踪此交付成果:
publish_artifactpublish_artifact(kind="article", channel="devto", title="<title>", url="<the REAL returned URL>", status="delivered")请使用实际返回的URL——切勿伪造。每个已发布的内容仅调用一次,且仅在确认交付成功后调用;如果发布失败,请跳过调用(或设置)。详情请查看。
status="failed"_shared/artifacts.md