ค้นหาโพสต์ที่ตรงกับคำค้นหาที่ระบุ ลองใช้เลยหรือดูตัวอย่าง
คุณจะต้องมีการให้สิทธิ์หากบล็อกที่ค้นหาเป็นบล็อกส่วนตัว
ส่งคำขอ
คำขอ HTTP
GET https://www.googleapis.com/blogger/v3/blogs/blogId/posts/search
พารามิเตอร์
| ชื่อพารามิเตอร์ | ค่า | คำอธิบาย |
|---|---|---|
| พารามิเตอร์ที่จำเป็น | ||
blogId |
string |
รหัสของบล็อกที่จะค้นหา |
q |
string |
คำค้นหาที่จะค้นหา |
| พารามิเตอร์ที่ไม่บังคับ | ||
fetchBodies |
boolean |
รวมเนื้อหาของโพสต์หรือไม่ หากต้องการลดการเข้าชม ให้ตั้งค่าพารามิเตอร์นี้เป็น false เมื่อไม่จำเป็นต้องใช้เนื้อหาในส่วนเนื้อหาของโพสต์
(ค่าเริ่มต้น: true)
|
orderBy |
string |
ลำดับการจัดเรียงที่ใช้กับผลการค้นหา
ค่าที่ยอมรับมีดังนี้
|
เนื้อความของคำขอ
อย่าระบุเนื้อหาคำขอด้วยเมธอดนี้
การตอบกลับ
หากทำสำเร็จ เมธอดนี้จะแสดงเนื้อหาการตอบกลับที่มีโครงสร้างดังต่อไปนี้
{
"kind": "blogger#postList",
"nextPageToken": string,
"items": [
posts Resource
]
}| ชื่อพร็อพเพอร์ตี้ | ค่า | คำอธิบาย | หมายเหตุ |
|---|---|---|---|
kind |
string |
ประเภทของเอนทิตีนี้ blogger#postList เสมอ |
|
nextPageToken |
string |
โทเค็นการแบ่งหน้าเพื่อดึงข้อมูลหน้าถัดไป หากมี | |
items[] |
list |
รายการโพสต์สำหรับบล็อกนี้ |
ตัวอย่าง
หมายเหตุ: ตัวอย่างโค้ดที่มีสำหรับวิธีการนี้ไม่ได้แสดงถึงภาษาโปรแกรมที่รองรับทั้งหมด (ดูรายการภาษาที่รองรับได้ในหน้าไลบรารีของไคลเอ็นต์)
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 ด้านล่างเพื่อเรียกเมธอดนี้ในข้อมูลสดและดูการตอบกลับ