โพสต์: ค้นหา

ค้นหาโพสต์ที่ตรงกับคำค้นหาที่ระบุ ลองเลยหรือดูตัวอย่าง

คุณจะต้องใช้การให้สิทธิ์หากบล็อกที่ค้นหาเป็นแบบส่วนตัว

ส่งคำขอ

คำขอ HTTP

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

พารามิเตอร์

ชื่อพารามิเตอร์ ค่า คำอธิบาย
พารามิเตอร์ที่จำเป็น
blogId string รหัสของบล็อกที่จะค้นหา
q string คำค้นหาที่ต้องการค้นหา
พารามิเตอร์ที่ไม่บังคับ
fetchBodies boolean รวมเนื้อหาเนื้อหาของโพสต์หรือไม่ หากต้องการลดการเข้าชมให้เหลือน้อยที่สุด ให้ตั้งค่าพารามิเตอร์นี้เป็น "เท็จ" เมื่อไม่จำเป็นต้องใช้เนื้อหาเนื้อหาของโพสต์ (ค่าเริ่มต้น: true)
orderBy string ลำดับการจัดเรียงที่ใช้กับผลการค้นหา

ค่าที่ยอมรับได้ มีดังนี้
  • "published": เรียงลำดับตามวันที่เผยแพร่โพสต์
  • "updated": เรียงลำดับตามวันที่ที่โพสต์ครั้งล่าสุด

เนื้อหาของคำขอ

โปรดอย่าให้เนื้อหาคำขอตามวิธีการนี้

คำตอบ

หากสำเร็จ เมธอดนี้จะแสดงเนื้อหาการตอบกลับซึ่งมีโครงสร้างต่อไปนี้

{
  "kind": "blogger#postList",
  "nextPageToken": string,
  "items": [
    posts Resource
  ]
}
ชื่อพร็อพเพอร์ตี้ ค่า คำอธิบาย Notes
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 ด้านล่างเพื่อเรียกใช้เมธอดนี้กับข้อมูลแบบสดและดูการตอบกลับ