csdn

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

csdn — read & publish on CSDN via your own cookies

csdn — 通过自有Cookie在CSDN上读写内容

Drives the user's real CSDN account through the same web APIs the site's own editor uses, authenticated by the login cookie they captured with the ACE extension. No browser, no third-party deps —
urllib
+
hmac
(the editor's save endpoint requires an HMAC signature, computed with stdlib).
The connector injects the cookie jar as an env var:
  • CSDN_COOKIES
    — a JSON array of cookies. Secret — never echo or print it. The CLI reads it for you.
CSDN fronts its APIs with a WAF; the CLI already sends a full browser fingerprint so reads aren't 403'd. If you still get a WAF 403, the cookie expired — have the user reconnect.
通过CSDN官网编辑器使用的相同Web API,驱动用户的真实CSDN账号,认证方式为用户通过ACE扩展捕获的登录Cookie。无需浏览器,无需第三方依赖——仅使用
urllib
+
hmac
(编辑器的保存接口需要HMAC签名,通过标准库计算)。
连接器将Cookie Jar注入为环境变量:
  • CSDN_COOKIES
    — 一个Cookie的JSON数组。保密内容——切勿回显或打印。 CLI会自动读取该变量。
CSDN的API由WAF防护;CLI已发送完整的浏览器指纹,因此读取操作不会返回403错误。如果仍收到WAF 403错误,说明Cookie已过期——请用户重新连接。

CLI

CLI

The skill ships
scripts/csdn.py
— self-contained, stdlib only.
sh
CSDN=$SKILL_DIR/scripts/csdn.py
python3 $CSDN whoami                       # who is logged in (+ total article count)
python3 $CSDN articles --limit 20          # my published articles + stats
python3 $CSDN article <article-id>         # one article's stats
Stats come straight from CSDN:
view_count
(阅读),
digg_count
(点赞),
comment_count
(评论),
collect_count
(收藏).
本技能附带了
scripts/csdn.py
——独立脚本,仅依赖标准库。
sh
CSDN=$SKILL_DIR/scripts/csdn.py
python3 $CSDN whoami                       # 查看当前登录用户(+ 文章总数)
python3 $CSDN articles --limit 20          # 查看我的已发布文章及统计数据
python3 $CSDN article <article-id>         # 查看单篇文章的统计数据
统计数据直接来自CSDN:
view_count
(阅读)、
digg_count
(点赞)、
comment_count
(评论)、
collect_count
(收藏)。

Verify the connection first

先验证连接

sh
python3 $CSDN whoami
sh
python3 $CSDN whoami

→ {"username": "...", "nickname": "...", "articles_total": 1597}

→ {"username": "...", "nickname": "...", "articles_total": 1597}


On a WAF 403 / auth error the cookie is expired — tell the user to reconnect at
<https://auth.acedata.cloud/user/connections>. Do **not** retry in a loop.

如果出现WAF 403/认证错误,说明Cookie已过期——告知用户前往<https://auth.acedata.cloud/user/connections>重新连接。**切勿循环重试。**

Publishing — GATED (dry-run unless trailing
--confirm
)

发布功能——受保护(除非末尾添加
--confirm
,否则仅为试运行)

publish
writes to the user's real account. Content is Markdown. Without a trailing
--confirm
it dry-runs.
--confirm
is honored only as the last argument. Always show the dry-run, get an explicit "yes", then re-run with
--confirm
last.
sh
python3 $CSDN publish --title "标题" --content-file a.md                      # dry-run
python3 $CSDN publish --title "标题" --content-file a.md --draft-only --confirm  # private draft (status=2)
python3 $CSDN publish --title "标题" --content-file a.md --tags "AI,Python" --confirm  # PUBLIC, goes live
  • --draft-only
    saves a private draft (CSDN
    status=2
    ) — safe, nothing public.
  • Without
    --draft-only
    the article is published publicly under the user's name. Default to
    --draft-only
    unless the user clearly asked to go live.
  • --tags
    is a comma-separated list of article tags.
publish
会写入用户的真实账号。内容格式为Markdown。如果末尾没有
--confirm
参数,仅进行试运行。
--confirm
仅在作为最后一个参数时生效。始终先展示试运行结果,获得用户明确的“确认”后,再添加
--confirm
参数重新运行。
sh
python3 $CSDN publish --title "标题" --content-file a.md                      # 试运行
python3 $CSDN publish --title "标题" --content-file a.md --draft-only --confirm  # 保存为私有草稿(status=2)
python3 $CSDN publish --title "标题" --content-file a.md --tags "AI,Python" --confirm  # 公开发布,立即上线
  • --draft-only
    :保存为私有草稿(CSDN的
    status=2
    )——安全,不会公开。
  • 若未添加
    --draft-only
    ,文章将以用户名义公开发布。除非用户明确要求上线,否则默认使用
    --draft-only
  • --tags
    :文章标签的逗号分隔列表。

Images

图片处理

publish
automatically re-hosts external markdown images (
![](url)
) onto CSDN's own CDN (
i-blog.csdnimg.cn
) before saving — CSDN 防盗链 blocks external images, and saving an article full of external URLs can even time out. Images already on
csdnimg.cn
are left alone; pass
--no-rehost-images
to skip. An image that fails to upload keeps its original URL (never blocks the post).
publish
会自动将Markdown中的外部图片(
![](url)
)重新托管到CSDN自己的CDN(
i-blog.csdnimg.cn
)后再保存——CSDN的防盗链会阻止外部图片,且保存包含大量外部URL的文章甚至可能超时。已在
csdnimg.cn
上的图片将保持不变;可通过
--no-rehost-images
参数跳过重新托管。上传失败的图片将保留原始URL(不会阻止文章发布)。

Gotchas — surface before the user is surprised

注意事项——提前告知用户避免意外

  • This is the user's real CSDN account. Confirm before any publish.
  • Cookie expiry / WAF 403: reconnect at auth.acedata.cloud/user/connections — never loop-retry a WAF block.
  • The editor save endpoint is signed with an HMAC key baked into CSDN's web bundle; if CSDN rotates it, publish fails loudly (reads still work).
  • Never print
    CSDN_COOKIES
    — it is full account access.
  • ToS: cookie automation acts only on the user's own account with their own captured cookie; the user owns that risk.
  • 这是用户的真实CSDN账号。发布前务必确认。
  • Cookie过期/WAF 403错误:前往auth.acedata.cloud/user/connections重新连接——切勿循环重试WAF拦截请求。
  • 编辑器的保存接口使用CSDN网页包中内置的HMAC密钥签名;如果CSDN轮换了该密钥,发布功能会直接失败(但读取功能仍可正常使用)。
  • 切勿打印
    CSDN_COOKIES
    ——该变量包含完整的账号访问权限。
  • 服务条款(ToS):Cookie自动化仅在用户自己的账号上操作,且使用用户自行捕获的Cookie;相关风险由用户自行承担。

Record the output

记录输出

After you successfully publish and obtain the live result URL, call the built-in
publish_artifact
tool ONCE so the user can track this deliverable in My Outputs:
publish_artifact(kind="article", channel="csdn", 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
status="failed"
) if publishing failed. See
_shared/artifacts.md
.
成功发布并获取到文章的实际访问URL后,调用内置的
publish_artifact
工具一次,以便用户在我的输出中跟踪该交付成果:
publish_artifact(kind="article", channel="csdn", title="<title>", url="<the REAL returned URL>", status="delivered")
使用实际返回的URL——切勿伪造。仅在确认交付成功后为每个已发布项目调用一次;如果发布失败,请跳过调用(或使用
status="failed"
)。详情请查看
_shared/artifacts.md