帖子: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
对结果应用的排序方向。
可接受的值包括:
<ph type="x-smartling-placeholder"></ph>
- “
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
]
}
属性名称 |
值 |
说明 |
备注 |
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();
}
试试看!
使用下面的 API Explorer 对实际数据调用此方法,然后查看响应。
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2024-08-21。
[null,null,["最后更新时间 (UTC):2024-08-21。"],[[["\u003cp\u003eRetrieves a list of posts from a specified blog, requiring authorization for private blogs but not for public ones.\u003c/p\u003e\n"],["\u003cp\u003eAllows filtering of posts by date, labels, status, and other criteria using optional parameters.\u003c/p\u003e\n"],["\u003cp\u003eSupports pagination to retrieve large lists of posts in manageable chunks.\u003c/p\u003e\n"],["\u003cp\u003eProvides options to control the inclusion of post bodies and image metadata for traffic optimization.\u003c/p\u003e\n"],["\u003cp\u003eReturns a response containing post details like title, author, publication date, content, and URL.\u003c/p\u003e\n"]]],[],null,["# Posts: list\n\nRetrieves a list of posts.\n[Try it now](#try-it) or [see an example](#examples).\n\n[Authorization](/blogger/docs/3.0/using#auth) is required if the posts are on a blog that is private. If the posts are on a blog that is public, then this method can be called without authorization.\n\nRequest\n-------\n\n### HTTP request\n\n```\nGET https://www.googleapis.com/blogger/v3/blogs/blogId/posts\n```\n\n### Parameters\n\n| Parameter name | Value | Description |\n|----------------|--------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| **Required parameters** |||\n| `blogId` | `string` | The ID of the blog to fetch posts from. |\n| **Optional parameters** |||\n| `endDate` | `datetime` | Latest post date to fetch, a `date-time` with [RFC 3339](http://www.ietf.org/rfc/rfc3339.txt\"\") formatting. |\n| `fetchBodies` | `boolean` | Whether the body content of posts is included (default: true). This should be set to false when the post bodies are not required, to help minimize traffic. (Default: `true`) |\n| `fetchImages` | `boolean` | Whether image URL metadata for each post is included. |\n| `labels` | `string` | Comma-separated list of labels to search for. |\n| `maxResults` | `unsigned integer` | Maximum number of posts to fetch. |\n| `orderBy` | `string` | Sort order applied to results. \u003cbr /\u003e \u003cbr /\u003e Acceptable values are: - \"`published`\": Order by the date the post was published - \"`updated`\": Order by the date the post was last updated |\n| `sortOption` | `string` | `UNAVAILABLE NOW` \u003cbr /\u003e \u003cbr /\u003e Sort direction applied to results. \u003cbr /\u003e \u003cbr /\u003e Acceptable values are: - \"`descending`\": Sort posts in descending order in time (default) - \"`ascending`\": Sort posts in ascending order in time |\n| `pageToken` | `string` | Continuation token if the request is paged. |\n| `startDate` | `datetime` | Earliest post date to fetch, a `date-time` with [RFC 3339](http://www.ietf.org/rfc/rfc3339.txt) formatting. |\n| `status` | `string` | Acceptable values are: - \"`draft`\": Draft posts - \"`live`\": Published posts - \"`scheduled`\": Posts that are scheduled to publish in future. |\n| `view` | `string` | Acceptable values are: - \"`ADMIN`\": Admin level detail - \"`AUTHOR`\": Author level detail - \"`READER`\": Reader level detail |\n\n### Request body\n\nDo not supply a request body with this method.\n\nResponse\n--------\n\nIf successful, this method returns a response body with the following structure:\n\n```objective-c\n{\n \"kind\": \"blogger#postList\",\n \"nextPageToken\": string,\n \"items\": [\n posts Resource\n ]\n}\n```\n\n| Property name | Value | Description | Notes |\n|-----------------|----------|---------------------------------------------------------|-------|\n| `kind` | `string` | The kind of this entity. Always `blogger#postList`. | |\n| `nextPageToken` | `string` | Pagination token to fetch the next page, if one exists. | |\n| `items[]` | `list` | The list of posts for this blog. | |\n\nExamples\n--------\n\n**Note:** The code examples available for this method do not represent all supported programming languages (see the [client libraries page](/blogger/docs/3.0/libraries) for a list of supported languages). \n\n### Java\n\nUses the [Java client library](http://code.google.com/p/google-api-java-client/) \n\n```java\n// The BlogId for the Blogger Buzz blog\nString BUZZ_BLOG_ID = \"2399953\";\n\n// Configure the Java API Client for Installed Native App\nHttpTransport HTTP_TRANSPORT = new NetHttpTransport();\nJsonFactory JSON_FACTORY = new JacksonFactory();\n\n// Configure the Installed App OAuth2 flow.\nCredential credential = OAuth2Native.authorize(HTTP_TRANSPORT,\n\tJSON_FACTORY, new LocalServerReceiver(),\n\tArrays.asList(BloggerScopes.BLOGGER));\n\n// Construct the Blogger API access facade object.\nBlogger blogger = Blogger.builder(HTTP_TRANSPORT, JSON_FACTORY)\n\t.setApplicationName(\"Blogger-PostsList-Snippet/1.0\")\n\t.setHttpRequestInitializer(credential).build();\n\n// The request action.\nList postsListAction = blogger.posts().list(BUZZ_BLOG_ID);\n\n// Restrict the result content to just the data we need.\npostsListAction.setFields(\"items(author/displayName,content,published,title,url),nextPageToken\");\n\n// This step sends the request to the server.\nPostList posts = postsListAction.execute();\n\n// Now we can navigate the response.\nint postCount = 0;\nint pageCount = 0;\nwhile (posts.getItems() != null && !posts.getItems().isEmpty()) {\n\tfor (Post post : posts.getItems()) {\n\t\tSystem.out.println(\"Post #\"+ ++postCount);\n\t\tSystem.out.println(\"\\tTitle: \"+post.getTitle());\n\t\tSystem.out.println(\"\\tAuthor: \"+post.getAuthor().getDisplayName());\n\t\tSystem.out.println(\"\\tPublished: \"+post.getPublished());\n\t\tSystem.out.println(\"\\tURL: \"+post.getUrl());\n\t\tSystem.out.println(\"\\tContent: \"+post.getContent());\n\t}\n\n\t// Pagination logic\n\tString pageToken = posts.getNextPageToken();\n\tif (pageToken == null || ++pageCount \u003e= 5) {\n\t\tbreak;\n\t}\n\tSystem.out.println(\"-- Next page of posts\");\n\tpostsListAction.setPageToken(pageToken);\n\tposts = postsListAction.execute();\n}\n```\n\nTry it!\n-------\n\n\nUse the APIs Explorer below to call this method on live data and see the response."]]