โพสต์: ค้นหา

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

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

ส่งคำขอ

คำขอ 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
  ]
}
ชื่อพร็อพเพอร์ตี้ ค่า คำอธิบาย หมายเหตุ
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 ด้านล่างเพื่อเรียกใช้วิธีการนี้สําหรับข้อมูลสดและดูการตอบกลับ