帖子:搜索

搜索符合指定查询字词的帖子。 立即试用查看示例

如果要搜索的博客是不公开的,则需要授权

请求

HTTP 请求

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

参数

参数名称 说明
必需参数
blogId string 要搜索的博客的 ID。
q string 要搜索的字词。
可选参数
fetchBodies boolean 是否包含帖子的正文内容。为了尽量减少流量,当不需要帖子的正文内容时,请将此参数设为 false。 (默认值:true
orderBy string 搜索结果的排序顺序。

可接受的值:
  • published”:按帖子发布日期排序
  • updated”:按帖子上次更新日期排序

请求正文

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

响应

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

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

示例

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

Java

使用 Java 客户端库

// The BlogId for the http://buzz.blogger.com/ 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-PostsSearch-Snippet/1.0")
.setHttpRequestInitializer(credential).build();
// The request action.
Search postsSearchAction = blogger.posts().search(BUZZ_BLOG_ID);
postsSearchAction.setQ("threaded comments");
// Restrict the result content to just the data we need.
postsSearchAction.setFields("items(content,published,title,url)");
// This step sends the request to the server.
PostList posts = postsSearchAction.execute();
// Now we can navigate the response.
if (posts.getItems() != null && !posts.getItems().isEmpty()) {
for (Post post : posts.getItems()) {
System.out.println("Title: " + post.getTitle());
System.out.println("Published: " + post.getPublished());
System.out.println("URL: " + post.getUrl());
System.out.println("Content: " + post.getContent());
}
}

试试看!

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