帖子:getByPath

按路径检索博文。 立即试用查看示例

如果博文位于私享博客上,则需要授权

博文路径是博文网址中位于主机之后的部分。例如,网址为 http://code.blogger.com/2011/09/blogger-json-api-now-available.html 的博文的路径为 /2011/09/blogger-json-api-now-available.html

请求

HTTP 请求

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

参数

参数名称 说明
必需参数
blogId string 要从中提取博文的博客的 ID。
path string 要检索的博文的路径。
可选参数
maxComments unsigned integer 为帖子检索的评论数量上限。如果未指定此参数,则不会在博文资源中返回任何评论。
view string

可接受的值包括:
  • ADMIN”:管理员级别详细信息
  • AUTHOR”:作者级别详细信息
  • READER”:管理员级别详细信息

请求正文

使用此方法时请勿提供请求正文。

响应

如果成功,此方法将在响应正文中返回一项 Posts 资源

示例

注意:此方法的代码示例并未列出所有受支持的编程语言(请参阅客户端库页面,查看受支持的语言列表)。

Java

使用 Java 客户端库

// The BlogId for the http://buzz.blogger.com/ blog.
String BUZZ_BLOG_ID = "2399953";

// The URL path component for a buzz post.
String BUZZ_POST_PATH = "/2012/01/engage-with-your-readers-through.html";

// 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-PostsGetByPath-Snippet/1.0")
        .setHttpRequestInitializer(credential).build();

// The request action.
GetByPath postsGetByPathAction = blogger.posts().getByPath(BUZZ_BLOG_ID);
postsGetByPathAction
.setPath(BUZZ_POST_PATH);

// Restrict the result content to just the data we need.
postsGetByPathAction
.setFields("content,published,title");

// This step sends the request to the server.
Post post = postsGetByPathAction.execute();

// Now we can navigate the response.
System.out.println("Title: " + post.getTitle());
System.out.println("Published: " + post.getPublished());
System.out.println("Content: " + post.getContent());