帖子:insert
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
需要授权
添加帖子。
立即试用或查看示例。
请求
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());
试试看!
使用下面的 API Explorer 对实际数据调用此方法,然后查看响应。
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2024-08-09。
[null,null,["最后更新时间 (UTC):2024-08-09。"],[[["\u003cp\u003eAdds a new post to a specified blog using the \u003ccode\u003ePOST\u003c/code\u003e method and requires authorization with the \u003ccode\u003ehttps://www.googleapis.com/auth/blogger\u003c/code\u003e scope.\u003c/p\u003e\n"],["\u003cp\u003eThe request body must contain a \u003ccode\u003ePosts resource\u003c/code\u003e specifying the post details, including title and content.\u003c/p\u003e\n"],["\u003cp\u003eSuccessful execution returns a \u003ccode\u003ePosts resource\u003c/code\u003e with details of the created post such as title, author, publication date, URL, and content.\u003c/p\u003e\n"],["\u003cp\u003eDevelopers can use various client libraries, like the Java client library shown in the example, to interact with the API.\u003c/p\u003e\n"],["\u003cp\u003eAn interactive API Explorer is available for users to test the method with live data and examine the responses directly.\u003c/p\u003e\n"]]],[],null,["# Posts: insert\n\n**Requires [authorization](#auth)**\n\nAdds a post.\n[Try it now](#try-it) or [see an example](#examples).\n\nRequest\n-------\n\n### HTTP request\n\n```\nPOST 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` | ID of the blog to add the post to. |\n| **Optional parameters** |||\n| `isDraft` | `boolean` | Whether to create the post as a draft |\n\n### Authorization\n\nThis request requires authorization with at least one of the following scopes ([read more about authentication and authorization](/blogger/docs/3.0/using#auth)).\n\n| Scope |\n|-------------------------------------------|\n| `https://www.googleapis.com/auth/blogger` |\n\n### Request body\n\nIn the request body, supply a [Posts resource](/blogger/docs/3.0/reference/posts#resource).\n\nResponse\n--------\n\nIf successful, this method returns a [Posts resource](/blogger/docs/3.0/reference/posts#resource) in the response body.\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 of a test blog.\nString TEST_BLOG_ID = \"8070105920543249955\";\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-PostsInsert-Snippet/1.0\")\n\t.setHttpRequestInitializer(credential).build();\n\n// Construct a post to insert\nPost content = new Post();\ncontent.setTitle(\"A test post\");\ncontent.setContent(\"With \u003ccode\u003eHTML\u003c/code\u003e content\");\n\n// The request action.\nInsert postsInsertAction = blogger.posts()\n\t.insert(TEST_BLOG_ID, content);\n\n// Restrict the result content to just the data we need.\npostsInsertAction.setFields(\"author/displayName,content,published,title,url\");\n\n// This step sends the request to the server.\nPost post = postsInsertAction.execute();\n\n// Now we can navigate the response.\nSystem.out.println(\"Title: \" + post.getTitle());\nSystem.out.println(\"Author: \" + post.getAuthor().getDisplayName());\nSystem.out.println(\"Published: \" + post.getPublished());\nSystem.out.println(\"URL: \" + post.getUrl());\nSystem.out.println(\"Content: \" + post.getContent());\n```\n\nTry it!\n-------\n\n\nUse the APIs Explorer below to call this method on live data and see the response."]]