Logo
Section 1 / 3

创建、更新和删除帖子

了解博客文章的相关知识,以及如何创建、更新和删除博客文章。

导入

创建、更新和删除帖子

了解博客文章的相关知识,以及如何创建、更新和删除博客文章。

参数类型描述
kindstring对象的类型。值:blogger#post。此值固定不变。
idstring文章的ID。
blogobject包含文章所属博客数据的对象。
blog.idstring文章所属博客的ID。
publisheddatetime文章的发布日期。格式:yyyy-mm-dd
updateddatetime文章最后一次更新的日期。格式:yyyy-mm-dd
urlstring文章的发布链接。
selfLinkstring文章的Blogger API URL。
titlestring文章的标题。
contentstring文章的内容。注意:该值可能包含HTML。
authorobject包含文章作者信息的对象。
author.idstring文章作者的ID。
author.displayNamestring文章作者的名称。
author.urlstring作者个人资料的发布链接。
author.imageobject包含作者头像信息的对象。
author.image.urlstring作者头像的URL。
repliesobject包含文章评论信息的对象。
replies.totalItemslong文章的评论总数。
replies.selfLinkstring文章评论的Blogger API URL。
labels[]list与文章关联的标签列表。
customMetaDatastring文章的元数据。
replies.items[]list文章的评论列表。
locationobject包含文章地理位置信息的对象。注意:仅当文章被标记了地理坐标时才可用。
location.namestring文章所在位置的名称。
location.latdouble文章位置的纬度。
location.lngdouble文章位置的经度。
location.spanstring文章位置的视图范围。
titleLinkstring标题的URL。
images[]list文章的展示图片。
images[].urlstring文章展示图片的URL。
statusstring文章的状态。注意:此值仅对管理员级别请求有效。
1https://blogger.googleapis.com/v3/blogs/{blogId}/posts

请求参数

参数类型类别描述
blogIdstring必需要添加文章的博客ID。
isDraftboolean可选决定是否将文章创建为草稿。允许值:true 表示创建为草稿,false 表示不创建为草稿。
1// 在此处定义导入库 2import fetch from 'node-fetch'; 3 4// 在此处定义访问令牌 5const ACCESS_TOKEN = '{{ACCESS_TOKEN}}'; 6 7// 在此处定义路径参数 8const blogId = '{{BLOG_ID}}'; 9 10// 在此处定义端点URL 11const endpointUrl = new URL(`https://blogger.googleapis.com/v3/blogs/${blogId}/posts`); 12 13// 在此处定义头参数 14const headerParameters = { 15 authorization: `Bearer ${ACCESS_TOKEN}`, 16 contentType: 'application/json', 17}; 18 19// 在此处定义查询参数 20const queryParameter = new URLSearchParams({ 21}); 22 23// 在此处定义请求体参数 24const bodyParameters = JSON.stringify({ 25 title: '', 26 content: '', 27}); 28 29// 设置API调用选项 30const options = { 31 method: 'POST', 32 headers: headerParameters, 33 body: bodyParameters, 34}; 35 36// 定义API调用函数 37async function createPost() { 38 try { 39 endpointUrl.search = queryParameter; 40 const response = await fetch(endpointUrl, options); 41 42 // 输出响应 43 printResponse(response); 44 } catch (error) { 45 // 输出错误信息 46 printError(error); 47 } 48} 49 50// 调用函数执行API调用 51createPost();
1https://blogger.googleapis.com/v3/blogs/{blogId}/posts/{postId}

请求参数

参数类型类别描述
blogIdstring必需要更新文章的博客ID。
postIdstring必需要更新的文章ID。
1// 在此处导入库 2import fetch from "node-fetch"; 3 4// 在此处定义访问令牌 5const ACCESS_TOKEN = '{{ACCESS_TOKEN}}'; 6 7// 在此处定义路径参数 8const blogId = '{{BLOG_ID}}'; 9const postId = '{{POST_ID}}'; 10 11// 在此处定义端点URL 12const endpointUrl = new URL(`https://blogger.googleapis.com/v3/blogs/${blogId}/posts/${postId}`); 13 14// 在此处定义头参数 15const headerParameters = { 16 authorization: `Bearer ${ACCESS_TOKEN}`, 17 contentType: 'application/json', 18}; 19 20// 在此处定义请求体参数 21const bodyParameters = JSON.stringify({ 22 title: '', 23}); 24 25// 设置API调用选项 26const options = { 27 method: 'PUT', 28 headers: headerParameters, 29 body: bodyParameters, 30}; 31 32// 定义API调用函数 33async function updatePost() { 34 try { 35 const response = await fetch(endpointUrl, options); 36 37 // 输出响应 38 printResponse(response); 39 } catch (error) { 40 // 输出错误信息 41 printError(error); 42 } 43} 44 45// 调用函数执行API调用 46updatePost();
1https://blogger.googleapis.com/v3/blogs/{blogId}/posts/{postId}

请求参数

参数类型类别描述
blogIdstring必需要删除文章的博客ID。
postIdstring必需要删除的文章ID。
1// 在此处定义访问令牌 2const ACCESS_TOKEN = '{{ACCESS_TOKEN}}'; 3 4// 在此处定义路径参数 5const blogId = '{{BLOG_ID}}'; 6 7// 在此处定义端点URL 8const endpointUrl = new URL('https://blogger.googleapis.com'); 9 10// 在此处定义头参数 11const headerParameters = { 12 authorization: `Bearer ${ACCESS_TOKEN}`, 13 contentType: 'application/json', 14}; 15 16// 设置API调用选项 17const options = { 18 method: 'DELETE', 19 headers: headerParameters, 20}; 21 22// 定义API调用函数 23async function deletePost() { 24 try { 25 // 创建一篇文章并获取其ID 26 const postId = await createPostAndGetId(); 27 if (!postId) 28 return; 29 endpointUrl.pathname = `/v3/blogs/${blogId}/posts/${postId}`; 30 const response = await fetch(endpointUrl, options); 31 32 // 输出响应 33 printResponse(response); 34 } catch (error) { 35 // 输出错误信息 36 printError(error); 37 } 38} 39 40// 调用函数执行API调用 41deletePost();

页面

发布和回滚帖子