註解:list

擷取貼文留言清單。 立即試用查看範例

如果留言的網誌設為私人,則必須授權才能刪除。如果留言位於公開網誌,則可不經授權呼叫這個方法。

要求

HTTP 要求

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

參數

參數名稱 說明
必要參數
blogId string 要擷取留言的網誌 ID。
postId string 要擷取留言的貼文 ID。
選用參數
endDate datetime 要擷取留言的最新日期,日期時間採用 RFC 3339 格式。
fetchBodies boolean 是否要納入留言內文。
maxResults unsigned integer 結果中要納入的留言數上限。
pageToken string 如果要求已分頁,則為接續符記。
startDate datetime 要擷取留言的最早日期,日期時間採用 RFC 3339 格式。
status string

可接受的值如下:
  • emptied」:內容已遭移除的留言
  • live」:公開顯示的留言
  • pending」:等待管理員核准的留言
  • spam」:管理員標示為垃圾內容的留言
view string

可接受的值如下:
  • ADMIN」:管理員層級詳細資料
  • AUTHOR」:作者層級詳細資料
  • READER」:管理員層級詳細資料

要求主體

請勿透過此方法提供要求主體。

回應

如果成功的話,這個方法會傳回回應內文,其結構如下:

{
  "kind": "blogger#commentList",
  "nextPageToken": string,
  "prevPageToken": string,
  "items": [
    comments Resource
  ]
}
屬性名稱 說明 附註
kind string 這個項目的種類。一律 blogger#commentList
nextPageToken string 用來擷取下一頁結果的分頁符記 (如有)。
prevPageToken string 用來擷取上一頁的分頁符記 (如有)。
items[] list 指定貼文的留言資源清單。

範例

注意:這個方法適用的程式設計語言眾多,我們只在此提供部分程式碼範例。如需查看所有支援語言,請參閱用戶端程式庫頁面

Java

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