Posts Resource
Operations on blog posts.
Methods
Get
Get a post by ID.
go
post, err := client.Posts().Get(ctx, blogId, postId)Query Parameters:
fetchBody— Include post contentfetchImages— Include post imagesmaxComments— Max comments to includeview— Access level
List
List posts for a blog.
go
posts, err := client.Posts().List(ctx, blogId,
blogger.WithMaxResults(10),
blogger.WithStatus(blogger.PostStatusLive),
blogger.WithOrderBy("published"),
)Query Parameters:
maxResults— Max results per pagepageToken— Pagination tokenstatus— Filter by status (LIVE,DRAFT,SCHEDULED,SOFT_TRASHED)labels— Filter by labelsstartDate— Start date filterendDate— End date filterfetchImages— Include post imagesorderBy— Sort by (PUBLISHED,UPDATED)sortOption— Sort direction (DESCENDING,ASCENDING)view— Access level
Search
Search posts by query.
go
posts, err := client.Posts().Search(ctx, blogId, "golang tutorial")Query Parameters:
q— Search query (required)fetchBodies— Include post contentorderBy— Sort order
GetByPath
Get a post by URL path.
go
post, err := client.Posts().GetByPath(ctx, blogId, "/2024/01/hello-world.html")Query Parameters:
path— URL path (required)view— Access levelmaxComments— Max comments to include
Insert
Create a new post.
go
post, err := client.Posts().Insert(ctx, blogId, &blogger.Post{
Title: "Hello World",
Content: "<p>My first post</p>",
})Query Parameters:
fetchBody— Include post contentisDraft— Create as draft
Update
Replace a post.
go
post, err := client.Posts().Update(ctx, blogId, postId, post)Patch
Partially update a post.
go
post, err := client.Posts().Patch(ctx, blogId, postId, post)Delete
Delete a post.
go
err := client.Posts().Delete(ctx, blogId, postId)Publish
Publish a post.
go
post, err := client.Posts().Publish(ctx, blogId, postId)Revert
Revert a published post to draft.
go
post, err := client.Posts().Revert(ctx, blogId, postId)Example
go
// List posts
posts, err := client.Posts().List(ctx, blogId,
blogger.WithMaxResults(10),
blogger.WithStatus(blogger.PostStatusLive),
blogger.WithOrderBy("published"),
)
// Search posts
posts, err = client.Posts().Search(ctx, blogId, "golang")
// Create post
post, err := client.Posts().Insert(ctx, blogId, &blogger.Post{
Title: "New Post",
Content: "<p>Content here</p>",
Labels: []string{"news", "updates"},
})