帖子: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,
  "items": [
    posts Resource
  ]
}
属性名称 说明 备注
kind string 此实体的种类。始终为 blogger#postList
nextPageToken string 用于获取下一页的分页令牌(如果存在)。
items[] list 此博客的帖子列表。

示例

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

Java

使用 Java 客户端库

// The BlogId for the Blogger Buzz blog String BUZZ_BLOG_ID = "2399953";
// Configure the Java API Client for Installed Native App
HttpTransport HTTP_TRANSPORT = new NetHttpTransport();
JsonFactory JSON_FACTORY = new JacksonFactory();
// Configure the Installed App OAuth2 flow.
Credential credential = OAuth2Native.authorize(HTTP_TRANSPORT,
JSON_FACTORY, new LocalServerReceiver(),
Arrays.asList(BloggerScopes.BLOGGER));
// Construct the Blogger API access facade object.
Blogger blogger = Blogger.builder(HTTP_TRANSPORT, JSON_FACTORY)
.setApplicationName("Blogger-PostsList-Snippet/1.0")
.setHttpRequestInitializer(credential).build();
// The request action.
List postsListAction = blogger.posts().list(BUZZ_BLOG_ID);
// Restrict the result content to just the data we need.
postsListAction.setFields("items(author/displayName,content,published,title,url),nextPageToken");
// This step sends the request to the server.
PostList posts = postsListAction.execute();
// Now we can navigate the response.
int postCount = 0;
int pageCount = 0;
while (posts.getItems() != null && !posts.getItems().isEmpty()) {
for (Post post : posts.getItems()) {
System.out.println("Post #"+ ++postCount);
System.out.println("\tTitle: "+post.getTitle());
System.out.println("\tAuthor: "+post.getAuthor().getDisplayName());
System.out.println("\tPublished: "+post.getPublished());
System.out.println("\tURL: "+post.getUrl());
System.out.println("\tContent: "+post.getContent());
}
// Pagination logic
String pageToken = posts.getNextPageToken();
if (pageToken == null || ++pageCount >= 5) {
break;
}
System.out.println("-- Next page of posts");
postsListAction.setPageToken(pageToken);
posts = postsListAction.execute();
}

试试看!

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