API 總覽
這裡提供 Boring API 的端點、驗證方式與通用使用規範。
基底網址
https://boring.aiagent-me.com
所有 API 請求都應指向此網址。
驗證方式
API Key 驗證
除了 OAuth 回呼之外,所有 API 請求都必須在標頭附上 API Key:
boring-api-key: boring_xxxxxxxxxxxxx
取得 API Key 的步驟:
- 登入 Boring 控制台
- 前往 Settings 頁面
- 點擊 「Generate New API Key」
- 複製並妥善保存金鑰
詳情請見 API 金鑰 章節。
請求格式
Content-Type
所有請求都必須包含:
Content-Type: application/json
Request Body
請求本體需為合法 JSON:
{
"post": {
"accountId": "uuid-string",
"content": {
"text": "Post content",
"mediaUrls": ["https://example.com/image.jpg"],
"platform": "facebook|instagram|threads"
},
"target": {
"targetType": "facebook|instagram|threads"
}
}
}
回應格式
成功回應
成功的回應皆會回傳 success: true:
{
"success": true,
"message": "Operation completed successfully",
"data": {
// 依端點而定
}
}
錯誤回應
錯誤時會回傳 success: false:
{
"success": false,
"error": "Error type",
"message": "Detailed error message"
}
常見 HTTP 狀態碼:
200:成功400:參數錯誤401:驗證失敗(API Key 無效)404:資源不存在500:伺服器錯誤
完整錯誤代碼請見 錯誤代碼。
端點一覽
發佈 API
| Method | Endpoint | 說明 | 驗證 |
|---|---|---|---|
| POST | /v2/posts |
對各平台發佈內容 | API Key |
詳見 發佈 章節。
帳號管理
| Method | Endpoint | 說明 | 驗證 |
|---|---|---|---|
| GET | /api/accounts |
列出已連結帳號 | Session |
| DELETE | /api/accounts/{id} |
解除連結 | Session |
| POST | /api/token/info |
驗證權杖資訊 | Session |
注意:以上端點需使用控制台登入的 Session Cookie,不接受 API Key。
發佈歷史
| Method | Endpoint | 說明 | 驗證 |
|---|---|---|---|
| GET | /api/published-posts |
取得發佈紀錄 | Session |
查詢參數:
limit:回傳筆數(預設 20,最多 100)
注意:同樣需控制台登入。
範例請求
發佈 Facebook 貼文
curl -X POST https://boring.aiagent-me.com/v2/posts \
-H "boring-api-key: boring_xxxxxxxxxxxxx" \
-H "Content-Type: application/json" \
-d '{
"post": {
"accountId": "facebook-account-id",
"content": {
"text": "Hello Facebook!",
"mediaUrls": ["https://example.com/photo.jpg"],
"platform": "facebook"
},
"target": {
"targetType": "facebook"
}
}
}'
驗證回應狀態
{
"success": true,
"message": "Post published successfully",
"data": {
"post_id": "...",
"platform": "facebook",
"post_type": "photo"
}
}
速率限制
速率限制依平台而異:
| 平台 | 限制 | 時間窗 |
|---|---|---|
| 200 次 | 每小時 | |
| 200 次 | 每小時 | |
| Threads | 250 次 | 每小時 |
| X(Twitter) | 300 次 | 3 小時 |
| YouTube | 10,000 units | 每日(配額制) |
超量時會收到:
{
"success": false,
"error": "RateLimitExceeded",
"message": "Rate limit exceeded. Try again in 3600 seconds.",
"retry_after": 3600
}
建議做法:
- 實作指數回退(exponential backoff)
- 可能時先行快取
- 在離峰時段批次處理
- 監控速率限制標頭
冪等性
目前尚未提供 idempotency key。重複發送相同請求會造成重複貼文。
建議:可使用回應中的 post_submission_id 自行實作去重邏輯。
分頁機制
目前只有發佈歷史支援分頁:
GET /api/published-posts?limit=20&offset=0
參數:
limit:每次回傳筆數(預設 20,最多 100)offset:略過前 N 筆(預設 0)
回應範例:
{
"posts": [...],
"total": 150,
"limit": 20,
"offset": 0
}
逾時設定
- 一般 API:60 秒
- 影片發佈:300 秒
- Threads 長串文:360 秒
若請求逾時:
- 前往發佈歷史確認是否成功
- 稍後再重試
- 若問題持續請聯絡支援
Webhook
目前尚未提供 Webhook。若要監控狀態,建議:
- 定期輪詢發佈歷史端點
- 於控制台檢視
- 透過自建日誌追蹤
API 版本
目前版本:v2
端點格式:
POST /v2/posts
汰除政策:
- 新版本發布後,舊版本保留 6 個月
- 會透過 email 通知下線時程
- 提供遷移指南
SDK 支援
官方 SDK:
- Python:即將推出
- JavaScript/Node.js:即將推出
- PHP:即將推出
目前請使用常見 HTTP 函式庫:
- Python:
requests - JavaScript:
fetch或axios - cURL:直接送出命令
程式範例請見 範例。
測試建議
測試帳號
請使用自己的測試帳號:
- 建立測試用 Facebook 粉專
- 使用 Instagram 測試帳號
- 建立額外 Threads 帳號
Sandbox 模式
目前 沒有 sandbox。所有呼叫都會發佈到真實帳號。
建議:
- 準備專用的測試帳號
- 測試環境使用獨立 API Key
- 以
[TEST]前綴標註測試貼文
最佳實務
1. 錯誤處理
try:
response = requests.post(API_URL, headers=headers, json=data)
result = response.json()
if not result.get("success"):
log_error(result["message"])
notify_admin(result)
return None
return result["data"]
except requests.exceptions.Timeout:
log_error("Request timed out")
# 重試邏輯
except requests.exceptions.RequestException as e:
log_error(f"Request failed: {e}")
# 處理網路錯誤
2. 重試機制
import time
def publish_with_retry(data, max_retries=3):
for attempt in range(max_retries):
try:
response = requests.post(API_URL, headers=headers, json=data)
result = response.json()
if result.get("success"):
return result
if result.get("error") == "RateLimitExceeded":
wait_time = result.get("retry_after", 60)
time.sleep(wait_time)
continue
except Exception as e:
if attempt == max_retries - 1:
raise
time.sleep(2 ** attempt) # 指數回退
return None
3. 紀錄日誌
import logging
logger = logging.getLogger(__name__)
logger.info(f"Publishing to {platform}: {account_id}")
response = requests.post(API_URL, headers=headers, json=data)
logger.info(f"Response: {response.status_code} - {response.text}")
4. 安全性
- 不要紀錄 API Key
- 使用環境變數 儲存敏感資訊
- 定期輪替金鑰
- 在自家伺服器設定 IP 白名單
- 全程使用 HTTPS
5. 效能
- 上傳前先壓縮圖片
- 使用 CDN 託管媒體
- 能批次時就批次請求
- 將帳號 ID 快取於本地
- 監控回應時間
支援服務
需要協助嗎?
- 文件:https://boring-doc.aiagent-me.com
- 控制台:https://boring.aiagent-me.com
- 問題回報:提交 issue 或聯絡客服