如果博客是私密博客,则需要进行授权。如果博客是公开博客,则无需授权即可调用此方法。
请求
HTTP 请求
GET https://www.googleapis.com/blogger/v3/blogs/blogId
参数
| 参数名称 | 值 | 说明 |
|---|---|---|
| 必需参数 | ||
blogId |
string |
要获取的博客的 ID。 |
| 可选参数 | ||
maxPosts |
unsigned integer |
要与博客一起检索的帖子数量上限。如果未指定此参数,则不会返回任何帖子作为博客资源的一部分。 |
请求正文
使用此方法时请勿提供请求正文。
响应
如果成功,此方法将在响应正文中返回 Blogs 资源。
示例
注意:此方法的代码示例并未涵盖所有支持的编程语言(请参阅客户端库页面,查看支持的语言清单)。
Java
使用 Java 客户端库
// The BlogId for the http://code.blogger.com/ blog.
String CODE_BLOG_ID = "3213900";
// Configure the Java API Client for Installed Native AppHttpTr
ansport HTTP_TRANSPORT = new NetHttpTransport();JsonFa
ctory JSON_FACTORY = new JacksonFactory(); class="devsite-syntax-c1">// Configure for the Installed App OAuth2 flow.Credential c
redential = OAuth2Native.authorize(HTTP_TRANSPORT, JSON_FACTOR
Y, new LocalServerReceiver(), Arrays.asLi
st(BloggerScopes.BLOGGER));span> <span class
="devsite-syntax-c1">// Construct the Blogger API access facade object.Blogger blogger =
Blogger.builder(HTTP_TRANSPORT, JSON_FACTORY) .setApplicationNa
me("Blogger-BlogGet-Snippet/1.0") .setHttpRequestIn
itializer(credential).build(); // This is the request action that you can configure before sending the request.Get blogGetAction = blog
ger.blogs().get(CODE_BLOG_ID); // Restrict the result content to just the data we need.blogGetAction.setFields("description,name,posts/totalItems,updated");// This step sends the r
equest to the server.Blog blog = blogGetActio
n.execute(); // Now we can navigate the response.System.out.println("Name
: "+blog.getName());System.out.println("Desc
ription: "+blog.getDescription());System.out.println("Post
Count: "+blog.getPosts().getTotalItems());System.out.println("Last
Updated: "+blog.getUpdated());an>
试试看!
使用下面的 API Explorer 对实际数据调用此方法,然后查看响应。