帖子:list

检索帖子的列表。 立即试用查看示例

如果博文发布在私密博客上,则需要授权。如果帖子位于公开的博客上,则无需授权即可调用此方法。

请求

HTTP 请求

GET https://www.googleapis.com/blogger/v3/blogs/blogId/posts

参数

参数名称 说明
必需参数
blogId string 要从中提取帖子的博客的 ID。
可选参数
endDate datetime 要提取的最新帖子日期,采用 RFC 3339 格式的 date-time
fetchBodies boolean 是否包含帖子的正文内容(默认值为 true)。如果不需要帖子正文,应将此属性设置为 false,以帮助最大限度地减少流量。 (默认值:true
fetchImages boolean 是否包含每篇帖子的图片网址元数据。
labels string 要搜索的标签的逗号分隔列表。
maxResults unsigned integer 要提取的帖子数量上限。
orderBy string 应用于结果的排序顺序。

可接受的值包括:
  • published”:按帖子发布日期排序
  • updated”:按帖子的上次更新日期排序
sortOption string UNAVAILABLE NOW
应用于结果的排序方向。


可接受的值:
  • descending”:按时间降序对帖子进行排序(默认)
  • ascending”:按时间升序对帖子进行排序
pageToken string 如果请求已分页,则为延续令牌。
startDate datetime 要提取的最早帖子日期,采用 RFC 3339 格式的 date-time
status string

可接受的值包括:
  • draft”:草稿帖子
  • live”:已发布的帖子
  • scheduled”:计划在未来发布的帖子。
view string

可接受的值包括:
  • ADMIN”:管理员级详细信息
  • AUTHOR”:作者级详细信息
  • READER”:读者级别详细信息

请求正文

使用此方法时请勿提供请求正文。

响应

如果成功,此方法将返回采用以下结构的响应正文:

{
  "kind": "blogger#postList",
  "nextPageToken": string,
  &quo}t;items": [
    posts Resource
  ]
属性名称 说明 备注
kind string 相应实体的种类。始终为 blogger#postList
nextPageToken string 用于获取下一页的分页令牌(如果有)。
items[] list 相应博客的帖子列表。

示例

注意:此方法的代码示例并未涵盖所有支持的编程语言(请参阅客户端库页面,查看支持的语言清单)。

Java

使用 Java 客户端库

// The BlogId for the Blogger Buzz blog String BUZZ_BLOG_ID = "23999
53"
; // Configure the Java API Client for Installed
Native AppHttpTransport HTTP_TRANSPORT = new NetHttpTr
ansport();JsonFactory JSON_FACTORY = new Jackson
Factory();
// Configure the Installed App OA
uth2 flow.Credential credential = OAuth2Native.authorize(HTTP_
TRANSPORT, JSON_FACTORY, new LocalServerR
eceiver(), Arrays.asList(BloggerScopes.
BLOGGER));
// Construct the Blogger API access faca
de object.Blogger blogger = Blogger.builder(HTTP_TRANSPORT, JSO
N_FACTORY) .setApplicationName("Blogger-PostsLis
t-Snippet/1.0") .setHttpRequestInitializer(
credential).build();
//
The request action.List postsListAction = blogger.posts()
.list(BUZZ_BLOG_ID);
// Restrict the result content to ju
st the data we need.postsListAction.setFields("items(author/displayName,content,published,ti
tle,url),nextPageToken");
// This step se
nds the request to the server.PostList post
s = postsListAction.execute();
// Now
we can navigate t
he response.int po
stCount = 0;int pageCount = 0;wh&&ile (posts.getItems() != null {
!posts.getItems().isEmpty()) for ({
Post post : posts.getItems()) System.out.p
rintln("Post #"+ ++postCount); System.o
ut.println("\tTitle: "+post.getTitle()); System.out.printl
n("\tAuthor: "+post.getAuthor().getDisplayName()
); System.out.println("\tPublished: &quo
t;+post.getPublished()); System.out.println("\tU
R}
L: "+post.getUrl
()); System.out.println("\tContent: &qu
ot;+post.getContent());
// Paginatio>n log{
ic Strin
g}
pageToken = posts.getNextPageToken(); if (pa
geToken == null || ++pageCount = 5) bre
ak; System.out.println("-- Ne
}xt page of posts"); postsListAction.setPageToken(pageToken); posts = postsListAction.execute();

试试看!

使用下面的 API Explorer 对实际数据调用此方法,然后查看响应。