公開情報 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" ] } ]}試してみる
レスポンスのフィールド
Section titled “レスポンスのフィールド”| フィールド | 型 | 説明 |
|---|---|---|
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" }}試してみる
レスポンスのフィールド
Section titled “レスポンスのフィールド”| フィールド | 型 | 説明 |
|---|---|---|
resources | object | key は 10 進文字列の 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
クエリパラメーター
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"}試してみる
レスポンスのフィールド
Section titled “レスポンスのフィールド”| フィールド | 型 | 説明 |
|---|---|---|
client_id | string | client id |
name | string | アプリ名。OAuth2 が発行した token は、この名前をメモにします |
description | string | アプリの説明。未設定のときは空文字列 |
- 圧縮:リソース対照表と OAuth2 client 情報は常に zstd で圧縮されます(
Content-Encoding: zstd)。扱い方は OAuth2 の注意事項を参照してください。権限一覧は未圧縮の JSON です。 - CORS:権限一覧は任意のオリジンを許可し、ブラウザから直接呼べます。リソース対照表と OAuth2 client 情報は公式サイトだけを許可するので、サーバー側から呼んでください。
- キャッシュ:権限一覧のレスポンスには
Cache-Control: public, max-age=300が付き、サーバー側も 300 秒キャッシュします。残りの 2 つのエンドポイントはサーバー側で 10 秒キャッシュします。 - 権限一覧は GET だけを受け付け、他のメソッドは 405 を返します。
- レスポンスの内容は、サーバーの更新時だけ変わります。プログラムの起動時に 1 回読んでキャッシュすればよく、リクエストのたびに問い合わせる必要はありません。
