Posts: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());

試試看!

您可以使用下方的 API Explorer,針對即時資料呼叫這個方法,然後查看回應。