blogger
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseCall the Blogger API v3 with . The user's OAuth bearer token is
in ; every call needs
. Base URL:
.
curl + jq$GOOGLE_BLOGGER_TOKENAuthorization: Bearer $GOOGLE_BLOGGER_TOKENhttps://www.googleapis.com/blogger/v3Errors are — show them verbatim.
→ token expired, re-connect the Blogger connector.
{"error": {"code": ..., "message": ...}}401Always start by listing the user's blogs to get a :
blogIdbash
curl -sS -H "Authorization: Bearer $GOOGLE_BLOGGER_TOKEN" \
"https://www.googleapis.com/blogger/v3/users/self/blogs" \
| jq '.items[] | {id, name, url}'使用调用Blogger API v3。用户的OAuth令牌存储在中;每次调用都需要携带。基础URL为:。
curl + jq$GOOGLE_BLOGGER_TOKENAuthorization: Bearer $GOOGLE_BLOGGER_TOKENhttps://www.googleapis.com/blogger/v3错误信息格式为——请原样展示。错误表示令牌过期,请重新连接Blogger连接器。
{"error": {"code": ..., "message": ...}}401始终先列出用户的博客以获取:
blogIdbash
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 (the default below) — do NOT silently save a draft
and stop. Only pass when the user explicitly asks for a
draft or to review before going public. After publishing, always report
the returned live back to the user.
?isDraft=false?isDraft=trueurlbash
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}'contentpandoc -f markdown -t html- Publish a staged draft: .
POST /blogs/{blogId}/posts/{postId}/publish - Update a post: with the same shape.
PUT /blogs/{blogId}/posts/{postId}
当用户要求发布/post/发布/发出去时,使用(如下默认值)将帖子实时发布——不要静默保存草稿后停止操作。仅当用户明确要求保存草稿或在公开前审核时,才传递。发布完成后,务必将返回的实时告知用户。
?isDraft=false?isDraft=trueurlbash
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}'contentpandoc -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 means the request carried no token (empty
403 "Method doesn't allow unregistered callers") — ask the user to (re)connect the Blogger connector, don't blame their Google Cloud setup.$GOOGLE_BLOGGER_TOKEN - An empty (no
{"kind":"blogger#blogList"}) 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.items - must be HTML; passing raw Markdown will render literally.
content - Paginate with from the previous
&pageToken=$PAGE_TOKEN..nextPageToken
- 在支持OAuth客户端的Google Cloud项目中启用Blogger API,否则调用会返回403错误,错误信息为。
accessNotConfigured - 若返回,表示请求未携带令牌(
403 "Method doesn't allow unregistered callers"为空)——请用户重新连接Blogger连接器,不要归咎于他们的Google Cloud配置。$GOOGLE_BLOGGER_TOKEN - 若返回空的(无
{"kind":"blogger#blogList"}字段),表示当前连接的Google账户未拥有任何博客——告知用户前往blogger.com创建博客,或使用拥有博客的账户重新连接。items - 必须是HTML格式;直接传入Markdown会被原样渲染。
content - 使用上一次返回结果中的作为
.nextPageToken进行分页。&pageToken=$PAGE_TOKEN
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="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 ) if publishing failed.
See .
status="failed"_shared/artifacts.md成功发布并获取实时结果URL后,调用一次内置的工具,以便用户在我的输出中跟踪此交付成果:
publish_artifactpublish_artifact(kind="article", channel="blogger", title="<title>", url="<the REAL returned URL>", status="delivered")请使用真实返回的URL——切勿伪造。每个已发布的项目仅调用一次,且仅在确认交付成功后调用;若发布失败,则跳过调用(或使用)。详情请查看。
status="failed"_shared/artifacts.md