Posts:list

擷取文章清單。 立即試用查看範例

如果該文章位於私人網誌中,就必須授權。如果貼文位於公開的網誌中,不必經過授權即可呼叫這個方法。

要求

HTTP 要求

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

參數

參數名稱 說明
必要參數
blogId string 擷取文章的來源網誌 ID。
選用參數
endDate datetime 要擷取的最後發布日期 (採用 RFC 3339 格式的 date-time)。
fetchBodies boolean 是否包含訊息的內文內容 (預設值:true)。如果不需要貼文內文,就應設為 false,以盡量減少流量。 (預設:true)
fetchImages boolean 是否包含每則貼文的圖片網址中繼資料。
labels string 要搜尋的標籤清單 (以半形逗號分隔)。
maxResults unsigned integer 可擷取的文章數量上限。
orderBy string 排序結果已套用至結果。

可接受的值如下:
  • published」:依照文章的發布日期排序
  • updated」:依照文章上次更新的日期排序
sortOption string UNAVAILABLE NOW

排序結果的排序方式。

可接受的值如下:
  • "descending":依時間遞減排序 (預設)
  • "ascending":按時間先後遞增排序
pageToken string 如果要求為分頁,則接續權杖。
startDate datetime 要擷取的最早日期,採用 RFC 3339 格式的 date-time
status string

可接受的值如下:
  • "draft":文章草稿
  • "live":已發布的文章
  • "scheduled":已排定發布時間的貼文。
view string

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

要求主體

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

回應

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

{
  "kind": "blogger#postList",
  "nextPageToken": string,
  "items": [
    posts Resource
  ]
}
屬性名稱 說明 Notes
kind string 這個實體的種類。一律為 blogger#postList
nextPageToken string 用於擷取下一頁的分頁符記 (如果有的話)。
items[] list 此網誌的文章清單。

範例

注意:這個方法適用的程式語言眾多,我們只在此提供部分程式碼範例,完整的支援語言清單請參閱用戶端程式庫頁面

Java

使用 Java 用戶端程式庫

// The BlogId for the Blogger Buzz 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-PostsList-Snippet/1.0")
.setHttpRequestInitializer(credential).build();
// The request action.
List postsListAction = blogger.posts().list(BUZZ_BLOG_ID);
// Restrict the result content to just the data we need.
postsListAction.setFields("items(author/displayName,content,published,title,url),nextPageToken");
// This step sends the request to the server.
PostList posts = postsListAction.execute();
// Now we can navigate the response.
int postCount = 0;
int pageCount = 0;
while (posts.getItems() != null && !posts.getItems().isEmpty()) {
for (Post post : posts.getItems()) {
System.out.println("Post #"+ ++postCount);
System.out.println("\tTitle: "+post.getTitle());
System.out.println("\tAuthor: "+post.getAuthor().getDisplayName());
System.out.println("\tPublished: "+post.getPublished());
System.out.println("\tURL: "+post.getUrl());
System.out.println("\tContent: "+post.getContent());
}
// Pagination logic
String pageToken = posts.getNextPageToken();
if (pageToken == null || ++pageCount >= 5) {
break;
}
System.out.println("-- Next page of posts");
postsListAction.setPageToken(pageToken);
posts = postsListAction.execute();
}

試試看!

使用 APIs Explorer 針對即時資料呼叫這個方法,並查看回應。