Posts:list

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

如果貼文位於私人網誌,則必須授權。如果文章位於公開網誌,則可直接呼叫這個方法,不必授權。

要求

HTTP 要求

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

參數

參數名稱 說明
必要參數
blogId string 要從中擷取文章的網誌 ID。
選用參數
endDate datetime 要擷取的最新貼文日期,格式為 date-time,並採用 RFC 3339 格式。
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 要擷取的最早貼文日期,採用 date-time 格式,並符合 RFC 3339 格式。
status string

可接受的值如下:
  • draft」:草擬貼文
  • live」:已發布的貼文
  • scheduled」:預定在未來發布的貼文。
view string

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

要求主體

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

回應

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

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

範例

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

Java

使用 Java 用戶端程式庫

// The BlogId for the Blogger Buzz blog String BUZZ_BLOG_ID = "23999
53"
; // Configure the Java API Client for Installed
Native AppHttpTransport HTTP_TRANSPORT = new NetHttpTr
ansport();JsonFactory JSON_FACTORY = new Jackson
Factory();
// Configure the Installed App OA
uth2 flow.Credential credential = OAuth2Native.authorize(HTTP_
TRANSPORT, JSON_FACTORY, new LocalServerR
eceiver(), Arrays.asList(BloggerScopes.
BLOGGER));
// Construct the Blogger API access faca
de object.Blogger blogger = Blogger.builder(HTTP_TRANSPORT, JSO
N_FACTORY) .setApplicationName("Blogger-PostsLis
t-Snippet/1.0") .setHttpRequestInitializer(
credential).build();
//
The request action.List postsListAction = blogger.posts()
.list(BUZZ_BLOG_ID);
// Restrict the result content to ju
st the data we need.postsListAction.setFields("items(author/displayName,content,published,ti
tle,url),nextPageToken");
// This step se
nds the request to the server.PostList post
s = postsListAction.execute();
// Now
we can navigate t
he response.int po
stCount = 0;int pageCount = 0;wh&&ile (posts.getItems() != null {
!posts.getItems().isEmpty()) for ({
Post post : posts.getItems()) System.out.p
rintln("Post #"+ ++postCount); System.o
ut.println("\tTitle: "+post.getTitle()); System.out.printl
n("\tAuthor: "+post.getAuthor().getDisplayName()
); System.out.println("\tPublished: &quo
t;+post.getPublished()); System.out.println("\tU
R}
L: "+post.getUrl
()); System.out.println("\tContent: &qu
ot;+post.getContent());
// Paginatio>n log{
ic Strin
g}
pageToken = posts.getNextPageToken(); if (pa
geToken == null || ++pageCount = 5) bre
ak; System.out.println("-- Ne
}xt page of posts"); postsListAction.setPageToken(pageToken); posts = postsListAction.execute();

試試看!

您可以使用下方的 API Explorer,針對即時資料呼叫這個方法,然後查看回應。