Bài đăng: chèn

Cần phải uỷ quyền

Thêm bài đăng. Thử ngay hoặc xem ví dụ.

Yêu cầu

Yêu cầu HTTP

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

Tham số

Tên thông số Giá trị Nội dung mô tả
Tham số bắt buộc
blogId string Mã của blog mà bạn muốn thêm bài đăng vào.
Tham số không bắt buộc
isDraft boolean Có tạo bài đăng dưới dạng bản nháp hay không

Ủy quyền

Yêu cầu này cần có sự uỷ quyền với ít nhất một trong các phạm vi sau (đọc thêm về tính năng xác thực và uỷ quyền).

Phạm vi
https://www.googleapis.com/auth/blogger

Nội dung yêu cầu

Trong phần nội dung yêu cầu, hãy cung cấp Tài nguyên bài đăng.

Phản hồi

Nếu thành công, phương thức này sẽ trả về một Tài nguyên bài đăng trong nội dung phản hồi.

Ví dụ

Lưu ý: Các đoạn mã mẫu của phương thức này không phải là ví dụ cho mọi ngôn ngữ lập trình được hỗ trợ (xem trang thông tin về các thư viện dùng cho ứng dụng để biết danh sách các ngôn ngữ được hỗ trợ).

Java

Dùng thư viện ứng dụng Java

// The BlogId of a test blog.
String TEST_BLOG_ID = "8070105920543249955";
// 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-PostsInsert-Snippet/1.0")
.setHttpRequestInitializer(credential).build();
// Construct a post to insert
Post content = new Post();
content.setTitle("A test post");
content.setContent("With <code>HTML</code> content");
// The request action.
Insert postsInsertAction = blogger.posts()
.insert(TEST_BLOG_ID, content);
// Restrict the result content to just the data we need.
postsInsertAction.setFields("author/displayName,content,published,title,url");
// This step sends the request to the server.
Post post = postsInsertAction.execute();
// Now we can navigate the response.
System.out.println("Title: " + post.getTitle());
System.out.println("Author: " + post.getAuthor().getDisplayName());
System.out.println("Published: " + post.getPublished()); System.out.println("URL: " + post.getUrl()); System.out.println("Content: " + post.getContent());

Hãy dùng thử!

Hãy sử dụng APIs Explorer (Trình khám phá API) bên dưới để gọi phương thức này trên dữ liệu trực tiếp và xem phản hồi.