3月 07, 2024 Google
到現在先發現原來 Google 係出過呢一種公開的 REST API 公開比人使用過。

### GData API Directory

Documentation : https://developers.google.com/gdata/docs/directory

之前幾個講 Blogger Live Search 的文章其實就是在用 GData API 去完成,所有的 URL Params 都有詳細的說明。

不過現在已經 Fadeout 左一大部份了,因為公開的 API 好難管理,現在大多都搬到 Cloud Platform 最少也要一條 API Key 才能使用。

這樣也比較安全,管理起來也比較容易。只要把 API Key revoke 就不用再回傳 API 了,能有部減少資源運用或者誤殺 IP 的情況。

### Blogger API v3

這個大約是十多年前的產物,是次搬 Blog 主要也是靠它來完成。

Documentation : https://developers.google.com/blogger/docs/3.0/getting_started

當中有大量 Endpoint 可以使用,如果只在 Client Side 使用者只要到 [Cloud Platform](https://cloud.google.com/) 開個 Project 申請一條 API Key 就可以使用了。

如果要是 `Create`, `Delete`, `Put`, `Patch` 操作就需要 OAuth 取得 Token 後,使用 Bearer token 方法來 Call API 才能做用。

好像是要實作 Search 功能的話,可以使用以下呢個 API 就行了:

```js
GET https://www.googleapis.com/blogger/v3/blogs/YOUR-BLOG-ID/posts/search?q=KEYWORD&key=YOUR-API-KEY
```

如果成功的話,就會收到 HTTP 200 及以下的 Response body:

```json
{
  "kind": "blogger#postList",
  "nextPageToken": "CgkIChiAj86CpB8QzJTEAQ",
  "items": [
  {
    "kind": "blogger#post",
    "id": "1387873546480002228",
    "blog": {
      "id": "3213900"
    },
    "published": "2012-03-23T01:58:00-07:00",
    "updated": "2012-03-23T01:58:12-07:00",
    "url": "http://code.blogger.com/2012/03/blogger-documentation-has-moved-to.html",
    "selfLink": "https://www.googleapis.com/blogger/v3/blogs/3213900/posts/1387873546480002228",
    "title": "Blogger Documentation has moved to developers.google.com",
    "content": "content elided for readability",
    "author": {
      "id": "16258312240222542576",
      "displayName": "Brett Morgan",
      "url": "http://www.blogger.com/profile/16258312240222542576",
      "image": {
        "url": "https://resources.blogblog.com/img/b16-rounded.gif"
      }
    },
    "replies": {
      "totalItems": "0",
      "selfLink": "https://www.googleapis.com/blogger/v3/blogs/3213900/posts/1387873546480002228/comments"
    }
  },
  ...
  ]
}
```

### 點樣 Call?

用 Axios 啦!

Git hub : https://github.com/axios/axios

有需要的話再寫其他文章講解。
過去文章
2025 (9)
4 (5)
3 (1)
2 (3)
2024 (25)
11 (3)
10 (3)
9 (1)
3 (18)
2022 (6)
10 (1)
6 (2)
5 (1)
3 (1)
1 (1)
2021 (21)
11 (7)
7 (1)
6 (2)
5 (2)
4 (6)
3 (2)
2 (1)
2020 (92)
12 (1)
11 (2)
10 (4)
9 (10)
8 (5)
7 (1)
6 (3)
5 (1)
4 (4)
3 (25)
2 (7)
1 (29)
2019 (57)
12 (25)
11 (7)
9 (25)