Posts:插入

需要授權

新增訊息。 立即試用查看範例

要求

HTTP 要求

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

參數

參數名稱 說明
必要參數
blogId string 要新增文章的網誌 ID。
選用參數
isDraft boolean 是否要建立貼文草稿

授權

此要求需要至少具備下列其中一個範圍的授權 (進一步瞭解驗證和授權)。

範圍
https://www.googleapis.com/auth/blogger

要求主體

在要求主體中提供貼文資源

回應

如果成功,此方法會在回應主體中傳回 Posts 資源

範例

注意:這個方法適用的程式語言眾多,我們只在此提供部分程式碼範例,完整的支援語言清單請參閱用戶端程式庫頁面

Java

使用 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());

試試看!

使用 APIs Explorer 針對即時資料呼叫這個方法,並查看回應。