貼文:搜尋

搜尋符合指定查詢字詞的貼文。 立即試用查看範例

如果搜尋的網誌設為私人,則必須取得授權

要求

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,針對即時資料呼叫這個方法,然後查看回應。