網誌:getByUrl

透過網址擷取網誌。 立即試用查看範例

如果網誌設為私人,則需要授權。如果是公開網誌,就可以在未經授權的情況下呼叫這個方法。

要求

HTTP 要求

GET https://www.googleapis.com/blogger/v3/blogs/byurl

參數

參數名稱 說明
必要參數
url string 要擷取的網誌網址。

要求主體

請勿使用這個方法提供請求主體。

回應

如果成功的話,這個方法會在回應內文中傳回網誌資源

範例

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

Java

使用 Java 用戶端程式庫

String CODE_BLOG_URL = "http://code.blogger.com/";

// 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-BlogGetByUrl-Snippet/1.0")
        .setHttpRequestInitializer(credential).build();

// The request action object.
GetByUrl blogGetByUrlAction = blogger.blogs().getByUrl();

// Configure which blog URL to look up.
blogGetByUrlAction
.setUrl(CODE_BLOG_URL);

// Restrict the result content to just the data we need.
blogGetByUrlAction
.setFields("description,name,posts/totalItems,updated");

// This step sends the request to the server.
Blog blog = blogGetByUrlAction.execute();

// Now we can navigate the response.
System.out.println("Name: " + blog.getName());
System.out.println("Description: " + blog.getDescription());
System.out.println("Post Count: " + blog.getPosts().getTotalItems());
System.out.println("Last Updated: " + blog.getUpdated());