公開資訊 API
這組 API 提供權限名稱、資源 id 對照與 OAuth2 client 的顯示資訊,給建立 token、處理用量或實作 OAuth2 的開發者使用。內容只在伺服器更新時改變,適合快取。
目前不需要 API Token。
取得權限清單
Section titled “取得權限清單”所有權限與群組的定義,主控台與 OAuth2 同意頁顯示的權限說明也來自這份資料。說明見權限。
GET
https://manager.exptech.com.tw/api/v1/info/permissions 伺服器Manager
curl "https://manager.exptech.com.tw/api/v1/info/permissions"const res = await fetch("https://manager.exptech.com.tw/api/v1/info/permissions");if (!res.ok) throw new Error(`HTTP ${res.status}`);const data = await res.json();console.log(data);import requests
res = requests.get("https://manager.exptech.com.tw/api/v1/info/permissions", timeout=10)res.raise_for_status()print(res.json())成功(未壓縮的 JSON)
{ "permissions": [ { "bit": 0, "name": "*", "description": "全部權限" }, { "bit": 1, "name": "account", "description": "帳號 API" }, { "bit": 2, "name": "trem.rts", "description": "TREM 即時測站", "resource_id": 1 }, { "bit": 3, "name": "trem.rtw", "description": "TREM 即時波形", "resource_id": 8 }, { "bit": 4, "name": "trem.raw", "description": "TREM 原始資料", "resource_id": 4 }, { "bit": 5, "name": "trem.eew", "description": "TREM 地震速報", "resource_id": 6 }, { "bit": 6, "name": "trem.intensity", "description": "TREM 震度", "resource_id": 7 }, { "bit": 7, "name": "trem.oeews", "description": "TREM 現地型" }, { "bit": 8, "name": "trem.control", "description": "TREM 控制 API", "resource_id": 5 }, { "bit": 10, "name": "eq.report", "description": "地震報告", "resource_id": 2 } ], "groups": [ { "name": "eq.*", "description": "地震全部", "includes": [ "eq.report" ] }, { "name": "trem.*", "description": "TREM 全部(不含控制 API)", "includes": [ "trem.rts", "trem.rtw", "trem.raw", "trem.eew", "trem.intensity", "trem.oeews" ] } ]}試試看
| 欄位 | 類型 | 說明 |
|---|---|---|
permissions | array | 所有權限,依 bit 由小到大排序 |
bit | number | 權限的內部編號。指定權限時請用 name,不要用編號 |
name | string | 權限名稱,用在主控台與 OAuth2 的 scope |
description | string | 顯示用說明 |
resource_id | number | 計量用的資源 id。不計量的權限沒有這個欄位 |
groups | array | 群組,依名稱排序 |
name | string | 群組名稱,例如 trem.* |
description | string | 顯示用說明 |
includes | string[] | 群組包含的權限名稱。涵蓋範圍以這個欄位為準,不要用名稱前綴推斷 |
取得資源對照表
Section titled “取得資源對照表”resource_id 與權限名稱的對照。用量與配額以資源為單位計算,需要把 resource_id 轉成名稱時查這張表。
GET
https://manager.exptech.com.tw/api/v1/info/resources 伺服器Manager
curl --compressed "https://manager.exptech.com.tw/api/v1/info/resources"const res = await fetch("https://manager.exptech.com.tw/api/v1/info/resources");if (!res.ok) throw new Error(`HTTP ${res.status}`);const data = await res.json();console.log(data);import requests
res = requests.get("https://manager.exptech.com.tw/api/v1/info/resources", timeout=10)res.raise_for_status()print(res.json())成功(zstd 壓縮的 JSON)
{ "resources": { "1": "trem.rts", "2": "eq.report", "4": "trem.raw", "5": "trem.control", "6": "trem.eew", "7": "trem.intensity", "8": "trem.rtw" }}試試看
| 欄位 | 類型 | 說明 |
|---|---|---|
resources | object | key 是十進位字串的 resource_id,value 是權限名稱。只包含會計量的權限;key 的順序不固定 |
取得 OAuth2 client 資訊
Section titled “取得 OAuth2 client 資訊”OAuth2 client 的顯示名稱與說明。不包含 secret、redirect_uri 或權限。
GET
https://manager.exptech.com.tw/api/v1/info/oauth-client 伺服器Manager
Query 參數
client_idOAuth2 client id
curl --compressed "https://manager.exptech.com.tw/api/v1/info/oauth-client?client_id=<client_id>"const params = new URLSearchParams({ client_id: "<client_id>" });const res = await fetch(`https://manager.exptech.com.tw/api/v1/info/oauth-client?${params}`);if (!res.ok) throw new Error(`HTTP ${res.status}`);const data = await res.json();console.log(data);import requests
res = requests.get( "https://manager.exptech.com.tw/api/v1/info/oauth-client", params={"client_id": "<client_id>"}, timeout=10,)res.raise_for_status()print(res.json())成功(zstd 壓縮的 JSON)
{ "client_id": "100001", "name": "Example Quake App", "description": "顯示即時地震資訊的範例 App"}沒帶 client_id(invalid_request),或 client 不存在(invalid_client)
{ "error": "invalid_client"}試試看
| 欄位 | 類型 | 說明 |
|---|---|---|
client_id | string | client id |
name | string | App 名稱。OAuth2 發出的 token 會以這個名稱作為備註 |
description | string | App 說明,沒有設定時為空字串 |
- 壓縮:資源對照表與 OAuth2 client 資訊一律以 zstd 壓縮(
Content-Encoding: zstd),處理方式見 OAuth2 注意事項。權限清單是未壓縮的 JSON。 - CORS:權限清單允許任何來源,可以在瀏覽器直接呼叫。資源對照表與 OAuth2 client 資訊只允許官方網站,請在伺服器端呼叫。
- 快取:權限清單回應帶
Cache-Control: public, max-age=300,伺服器端也會快取 300 秒;另外兩個端點伺服器端快取 10 秒。 - 權限清單只接受 GET,其他方法回 405。
- 回應內容只在伺服器更新時改變。程式啟動時讀一次並快取即可,不需要每次請求都查。
