เรียกข้อมูลรายการความคิดเห็นสำหรับโพสต์ ลองใช้เลยหรือดูตัวอย่าง
ต้องมีการให้สิทธิ์หากความคิดเห็นอยู่ในบล็อกที่เป็นแบบส่วนตัว หากความคิดเห็นอยู่ในบล็อกที่เป็นแบบสาธารณะ ก็จะเรียกใช้เมธอดนี้ได้โดยไม่ต้องมีการให้สิทธิ์
ส่งคำขอ
คำขอ HTTP
GET https://www.googleapis.com/blogger/v3/blogs/blogId/posts/postId/comments
พารามิเตอร์
| ชื่อพารามิเตอร์ | ค่า | คำอธิบาย |
|---|---|---|
| พารามิเตอร์ที่จำเป็น | ||
blogId |
string |
รหัสของบล็อกที่จะดึงความคิดเห็น |
postId |
string |
รหัสของโพสต์ที่จะดึงความคิดเห็น |
| พารามิเตอร์ที่ไม่บังคับ | ||
endDate |
datetime |
วันที่ล่าสุดของความคิดเห็นที่จะดึงข้อมูล ซึ่งเป็นวันที่และเวลาที่มีการจัดรูปแบบ RFC 3339 |
fetchBodies |
boolean |
รวมเนื้อหาของความคิดเห็นหรือไม่ |
maxResults |
unsigned integer |
จำนวนความคิดเห็นสูงสุดที่จะรวมไว้ในผลลัพธ์ |
pageToken |
string |
โทเค็นการต่อเนื่องหากคำขอมีการแบ่งหน้า |
startDate |
datetime |
วันที่เก่าที่สุดของความคิดเห็นที่จะดึงข้อมูล ซึ่งเป็นวันที่และเวลาที่มีการจัดรูปแบบ RFC 3339 |
status |
string |
ค่าที่ยอมรับมีดังนี้
|
view |
string |
ค่าที่ยอมรับมีดังนี้
|
เนื้อความของคำขอ
อย่าระบุเนื้อหาคำขอด้วยเมธอดนี้
การตอบกลับ
หากทำสำเร็จ เมธอดนี้จะแสดงเนื้อหาการตอบกลับที่มีโครงสร้างดังต่อไปนี้
{
"kind": "blogger#commentList",
"nextPageToken": string,
"prevPageToken": string,
"items": [
comments Resource
]
}| ชื่อพร็อพเพอร์ตี้ | ค่า | คำอธิบาย | หมายเหตุ |
|---|---|---|---|
kind |
string |
ประเภทของรายการนี้ เสมอ blogger#commentList |
|
nextPageToken |
string |
โทเค็นการแบ่งหน้าเพื่อดึงข้อมูลหน้าถัดไป หากมี | |
prevPageToken |
string |
โทเค็นการแบ่งหน้าเพื่อดึงข้อมูลหน้าก่อนหน้า หากมี | |
items[] |
list |
รายการแหล่งข้อมูลความคิดเห็นสำหรับโพสต์ที่ระบุ |
ตัวอย่าง
หมายเหตุ: ตัวอย่างโค้ดที่มีสำหรับวิธีการนี้ไม่ได้แสดงถึงภาษาโปรแกรมที่รองรับทั้งหมด (ดูรายการภาษาที่รองรับได้ในหน้าไลบรารีของไคลเอ็นต์)
Java
// The BlogId for the http://buzz.blogger.com/ blog.
String BUZZ_BLOG_ID = "2399953";
// The PostId for a buzz post with comments.
String BUZZ_POST_ID = "5310628572012276714";
// 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-CommentsList-Snippet/1.0")
.setHttpRequestInitializer(credential).build();
// The request action.
List commentsListAction = blogger.comments().list(BUZZ_BLOG_ID, BUZZ_POST_ID);
// Restrict the result content to just the data we need.
commentsListAction.setFields("items(author/displayName,content),nextPageToken");
// This step sends the request to the server.
CommentList comments = commentsListAction.execute();
// Now we can navigate the response.
while(comments.getItems() != null && !comments.getItems().isEmpty()){
for(Comment comment : comments.getItems()) {
System.out.println(comment.getAuthor().getDisplayName()+": "+comment.getContent());
}
// Pagination logic
String pageToken = comments.getNextPageToken();
if(pageToken == null) {
break;
}
System.out.println("-- Next page of comments");
commentsListAction.setPageToken(pageToken);
comments = commentsListAction.execute();}
ลองใช้งาน
ใช้โปรแกรมสำรวจ API ด้านล่างเพื่อเรียกเมธอดนี้ในข้อมูลสดและดูการตอบกลับ