blogger

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese
Call the Blogger API v3 with
curl + jq
. The user's OAuth bearer token is in
$GOOGLE_BLOGGER_TOKEN
; every call needs
Authorization: Bearer $GOOGLE_BLOGGER_TOKEN
. Base URL:
https://www.googleapis.com/blogger/v3
.
Errors are
{"error": {"code": ..., "message": ...}}
— show them verbatim.
401
→ token expired, re-connect the Blogger connector.
Always start by listing the user's blogs to get a
blogId
:
bash
curl -sS -H "Authorization: Bearer $GOOGLE_BLOGGER_TOKEN" \
  "https://www.googleapis.com/blogger/v3/users/self/blogs" \
  | jq '.items[] | {id, name, url}'
使用
curl + jq
调用Blogger API v3。用户的OAuth令牌存储在
$GOOGLE_BLOGGER_TOKEN
中;每次调用都需要携带
Authorization: Bearer $GOOGLE_BLOGGER_TOKEN
。基础URL为:
https://www.googleapis.com/blogger/v3
错误信息格式为
{"error": {"code": ..., "message": ...}}
——请原样展示。
401
错误表示令牌过期,请重新连接Blogger连接器。
始终先列出用户的博客以获取
blogId
bash
curl -sS -H "Authorization: Bearer $GOOGLE_BLOGGER_TOKEN" \
  "https://www.googleapis.com/blogger/v3/users/self/blogs" \
  | jq '.items[] | {id, name, url}'

Publish a post

发布帖子

When the user asks to publish / post / 发布 / 发出去, publish it live with
?isDraft=false
(the default below) — do NOT silently save a draft and stop. Only pass
?isDraft=true
when the user explicitly asks for a draft or to review before going public. After publishing, always report the returned live
url
back to the user.
bash
BLOG_ID="1234567890"
jq -n --arg t "My title" --arg c "<p>HTML content of the post…</p>" \
  '{kind:"blogger#post", title:$t, content:$c, labels:["ai","video"]}' \
| curl -sS -X POST \
    "https://www.googleapis.com/blogger/v3/blogs/$BLOG_ID/posts/?isDraft=false" \
    -H "Authorization: Bearer $GOOGLE_BLOGGER_TOKEN" \
    -H "Content-Type: application/json" \
    -d @- \
| jq '{id, url, status}'
content
is HTML (not Markdown) — convert Markdown to HTML first (e.g. with
pandoc -f markdown -t html
or a simple converter).
  • Publish a staged draft:
    POST /blogs/{blogId}/posts/{postId}/publish
    .
  • Update a post:
    PUT /blogs/{blogId}/posts/{postId}
    with the same shape.
当用户要求发布/post/发布/发出去时,使用
?isDraft=false
(如下默认值)将帖子实时发布——不要静默保存草稿后停止操作。仅当用户明确要求保存草稿或在公开前审核时,才传递
?isDraft=true
。发布完成后,务必将返回的实时
url
告知用户。
bash
BLOG_ID="1234567890"
jq -n --arg t "My title" --arg c "<p>HTML content of the post…</p>" \
  '{kind:"blogger#post", title:$t, content:$c, labels:["ai","video"]}' \
| curl -sS -X POST \
    "https://www.googleapis.com/blogger/v3/blogs/$BLOG_ID/posts/?isDraft=false" \
    -H "Authorization: Bearer $GOOGLE_BLOGGER_TOKEN" \
    -H "Content-Type: application/json" \
    -d @- \
| jq '{id, url, status}'
content
必须是HTML格式(而非Markdown)——需先将Markdown转换为HTML(例如使用
pandoc -f markdown -t html
或简单的转换工具)。
  • 发布已存草稿:
    POST /blogs/{blogId}/posts/{postId}/publish
  • 更新帖子:使用相同格式调用
    PUT /blogs/{blogId}/posts/{postId}

List / read posts

列出/读取帖子

bash
curl -sS -H "Authorization: Bearer $GOOGLE_BLOGGER_TOKEN" \
  "https://www.googleapis.com/blogger/v3/blogs/$BLOG_ID/posts?maxResults=20&status=live" \
  | jq '.items[] | {id, title, url, published}'
bash
curl -sS -H "Authorization: Bearer $GOOGLE_BLOGGER_TOKEN" \
  "https://www.googleapis.com/blogger/v3/blogs/$BLOG_ID/posts?maxResults=20&status=live" \
  | jq '.items[] | {id, title, url, published}'

Gotchas

注意事项

  • Enable the Blogger API on the Google Cloud project backing the OAuth client, or calls 403 with
    accessNotConfigured
    .
  • A
    403 "Method doesn't allow unregistered callers"
    means the request carried no token (empty
    $GOOGLE_BLOGGER_TOKEN
    ) — ask the user to (re)connect the Blogger connector, don't blame their Google Cloud setup.
  • An empty
    {"kind":"blogger#blogList"}
    (no
    items
    ) means the connected Google account owns no blog — tell the user to create one at blogger.com or reconnect with the account that has the blog.
  • content
    must be HTML; passing raw Markdown will render literally.
  • Paginate with
    &pageToken=$PAGE_TOKEN
    from the previous
    .nextPageToken
    .
  • 在支持OAuth客户端的Google Cloud项目中启用Blogger API,否则调用会返回403错误,错误信息为
    accessNotConfigured
  • 若返回
    403 "Method doesn't allow unregistered callers"
    ,表示请求未携带令牌(
    $GOOGLE_BLOGGER_TOKEN
    为空)——请用户重新连接Blogger连接器,不要归咎于他们的Google Cloud配置。
  • 若返回空的
    {"kind":"blogger#blogList"}
    (无
    items
    字段),表示当前连接的Google账户未拥有任何博客——告知用户前往blogger.com创建博客,或使用拥有博客的账户重新连接。
  • content
    必须是HTML格式;直接传入Markdown会被原样渲染。
  • 使用上一次返回结果中的
    .nextPageToken
    作为
    &pageToken=$PAGE_TOKEN
    进行分页。

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="blogger", 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="blogger", title="<title>", url="<the REAL returned URL>", status="delivered")
请使用真实返回的URL——切勿伪造。每个已发布的项目仅调用一次,且仅在确认交付成功后调用;若发布失败,则跳过调用(或使用
status="failed"
)。详情请查看
_shared/artifacts.md