如果留言是位於私人網誌上,則必須取得授權。如果是公開網誌的留言,則無需授權即可呼叫此方法。
要求
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 | 可接受的值為: 
 | 
| view | string | 可接受的值為: 
 | 
要求主體
請勿使用這個方法提供請求主體。
回應
如果成功的話,這個方法會傳回回應內文,其結構如下:
{
  "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();}
試試看!
使用下方的 APIs Explorer,針對即時資料呼叫這個方法,看看會有什麼結果。
