注释: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 针对实际数据调用此方法并查看响应。