Facebook 發佈
了解如何連結 Facebook 粉絲專頁,並透過 Boring 發佈各式內容到 Facebook。
連結粉絲專頁
前置需求
- 一個 Facebook 帳號
- 至少一個粉絲專頁的管理員權限
- 已登入 Boring 控制台
連結步驟
- 在控制台按下 「Connect Facebook Page」
- 如尚未登入 Facebook,請先登入
- 選擇要連結的粉絲專頁
- 檢視並授予必要權限:
pages_show_list:查看粉絲專頁列表pages_read_engagement:讀取互動數據pages_manage_posts:發佈與管理貼文pages_read_user_content:讀取粉絲專頁內容
- 點擊 「Done」 完成授權
完成後,粉絲專頁會顯示在「Authorized Accounts」列表,包含:
- 粉絲專頁名稱
- 平台標籤(Facebook)
- 唯一帳號 ID(可透過「Copy ID」複製)
- 解除連結選項
權杖資訊
- 權杖類型:長期粉絲專頁存取權杖
- 到期時間:永不過期
- 資料存取期限:90 天(期滿需重新授權)
- 自動續期:不需要
支援的內容類型
Facebook 透過 Boring 支援以下貼文型態:
| 類型 | 說明 | 媒體數量 | 範例 |
|---|---|---|---|
| 文字 | 純文字貼文 | 0 | 公告、狀態更新 |
| 照片 | 單張圖片貼文 | 1 | 產品照、活動海報 |
| 相簿 | 多張圖片貼文 | 2-10 | 活動花絮、步驟教學 |
| 影片 | 影片貼文 | 1 | 教學影片、產品示範 |
發佈範例
1. 純文字貼文
{
"post": {
"accountId": "your-facebook-page-account-id",
"content": {
"text": "Hello from Boring API! This is a text-only post.",
"mediaUrls": [],
"platform": "facebook"
},
"target": {
"targetType": "facebook"
}
}
}
效果:在粉絲專頁發布一則純文字貼文。
2. 單張照片貼文
{
"post": {
"accountId": "your-facebook-page-account-id",
"content": {
"text": "Check out this amazing photo!",
"mediaUrls": ["https://example.com/image.jpg"],
"platform": "facebook"
},
"target": {
"targetType": "facebook"
}
}
}
效果:附帶一張圖片與文字說明的貼文。
媒體規格:
- 格式:JPG、PNG
- 建議大小:4MB 以下
- 長寬比:不限(建議 1:1)
- URL:需可公開存取
3. 相簿貼文(多圖)
{
"post": {
"accountId": "your-facebook-page-account-id",
"content": {
"text": "Here's a collection of our best moments!",
"mediaUrls": [
"https://example.com/photo1.jpg",
"https://example.com/photo2.jpg",
"https://example.com/photo3.jpg",
"https://example.com/photo4.jpg"
],
"platform": "facebook"
},
"target": {
"targetType": "facebook"
}
}
}
效果:建立含多張圖片的相簿貼文。
相簿限制:
- 最少 2 張、最多 10 張
- 所有圖片皆需為有效 URL
- 支援格式:JPG、PNG
- 單張建議大小 4MB 以下
4. 影片貼文
{
"post": {
"accountId": "your-facebook-page-account-id",
"content": {
"text": "Watch this incredible video!",
"mediaUrls": ["https://example.com/video.mp4"],
"platform": "facebook"
},
"target": {
"targetType": "facebook"
}
}
}
效果:附帶影片與文字說明的貼文。
影片規格:
- 格式:MP4、MOV
- 檔案大小:最多 1GB
- 影片長度:最長 240 分鐘
- 建議長寬比:16:9 或 9:16
- URL:需可公開存取
API 請求格式
完整範例
import requests
API_URL = "https://boring.aiagent-me.com/v2/posts"
API_KEY = "boring_xxxxxxxxxxxxx"
ACCOUNT_ID = "your-facebook-page-account-id"
# 相簿貼文範例
post_data = {
"post": {
"accountId": ACCOUNT_ID,
"content": {
"text": "Summer collection 2025! 🌞",
"mediaUrls": [
"https://storage.example.com/summer1.jpg",
"https://storage.example.com/summer2.jpg",
"https://storage.example.com/summer3.jpg"
],
"platform": "facebook"
},
"target": {
"targetType": "facebook"
}
}
}
headers = {
"boring-api-key": API_KEY,
"Content-Type": "application/json"
}
response = requests.post(API_URL, headers=headers, json=post_data)
print(response.json())
成功回應
{
"success": true,
"message": "Post published successfully",
"data": {
"post_id": "123456789_987654321",
"post_type": "album",
"platform": "facebook",
"page_name": "My Awesome Page",
"photo_count": 3,
"published_at": "2025-01-20T10:30:00Z"
}
}
媒體 URL 要求
上傳媒體的方式
媒體 URL 必須符合:
- 可公開存取(不需任何登入)
- 直接指向檔案(非 HTML 頁面)
- 使用 HTTPS(HTTP 會自動升級)
- 確實存在且可下載(避免 404)
推薦的媒體託管服務
- Google Cloud Storage(公開 bucket)
- AWS S3(公開 bucket)
- Cloudinary
- Imgur
- 任何可公開存取的自有伺服器
測試媒體 URL
發佈前可使用 cURL 測試:
curl -I https://example.com/image.jpg
應該會得到類似以下結果:
HTTP/2 200
content-type: image/jpeg
content-length: 123456
疑難排解
常見錯誤
錯誤:「Invalid account_id」
- 原因:帳號 ID 不存在或不屬於目前使用者
- 解法:重新在控制台複製正確的帳號 ID
錯誤:「Failed to download media」
- 原因:媒體 URL 無法存取
- 解法:
- 確認 URL 可公開下載
- 檢查回傳的內容型態是否正確
- 保證不需額外驗證即可取用
錯誤:「Invalid media type」
- 原因:檔案格式不支援
- 解法:圖片轉為 JPG/PNG,影片轉為 MP4
錯誤:「Token expired」
- 原因:資料存取權限已逾 90 天
- 解法:在控制台重新連結粉絲專頁
最佳實務
- 先以純文字測試:確認流程無誤後再加入媒體
- 使用可靠的媒體託管:避免臨時或會過期的 URL
- 事前驗證媒體 URL:確保可下載且格式正確
- 維持精簡文案:Facebook 建議 1-2 個段落
- 採用高品質圖片:建議至少 1200x630
- 監控發佈紀錄:於控制台查看錯誤訊息
發佈歷史
在控制台查看所有 Facebook 貼文:
- 登入 Boring 控制台
- 捲動至 「Recent Posts」 區塊
- 需要時可依平台篩選
每筆紀錄會顯示:
- 貼文類型(文字、照片、相簿、影片)
- 內容預覽
- 狀態(成功/失敗)
- 發佈時間
- 若失敗則顯示錯誤訊息
速率限制
Facebook API 具備以下速率限制:
- 每個粉絲專頁:每小時 200 次呼叫
- 每位使用者:每小時 200 次呼叫
Boring 會妥善處理速率限制,一旦達到限制會回傳相應錯誤。
進階功能
管理多個粉絲專頁
你可以在同一個 Boring 帳號中連結多個粉絲專頁,每個專頁都有獨立的帳號 ID。
操作範例:
- 連結粉絲專頁 A(帳號 ID:
aaa-111) - 連結粉絲專頁 B(帳號 ID:
bbb-222) - 使用
accountId: "aaa-111"發佈至粉絲專頁 A - 使用
accountId: "bbb-222"發佈至粉絲專頁 B
跨平台同步發佈
可同時在 Facebook、Instagram、Threads 發佈相同內容:
accounts = [
"facebook-page-account-id",
"instagram-account-id",
"threads-account-id"
]
for account_id in accounts:
# 依平台調整內容
post_data = create_post_data(account_id, platform)
response = requests.post(API_URL, headers=headers, json=post_data)
留言 API
Boring 提供 API 端點,可在 Facebook 貼文下留言以及取得貼文留言。
發表留言
使用已連結的粉絲專頁在 Facebook 貼文下留言。
POST /api/fb/comment
請求標頭:
| 標頭 | 必填 | 說明 |
|---|---|---|
boring-api-key |
是 | 你的 API 金鑰 |
Content-Type |
是 | application/json |
請求內容:
| 欄位 | 類型 | 必填 | 說明 |
|---|---|---|---|
account_id |
string | 是 | Facebook 粉絲專頁帳號 ID |
post_id |
string | 是 | Facebook 貼文 ID(格式:pageId_postId) |
message |
string | 是 | 留言內容 |
範例:
curl -X POST https://boring.aiagent-me.com/api/fb/comment \
-H "boring-api-key: boring_xxxxxxxxxxxxx" \
-H "Content-Type: application/json" \
-d '{
"account_id": "your-facebook-page-account-id",
"post_id": "123456789_987654321",
"message": "好文章!感謝分享。"
}'
成功回應:
{
"success": true,
"comment_id": "123456789",
"post_id": "123456789_987654321",
"message": "好文章!感謝分享。",
"page_name": "我的粉絲專頁"
}
Python 範例:
import requests
API_URL = "https://boring.aiagent-me.com"
API_KEY = "boring_xxxxxxxxxxxxx"
ACCOUNT_ID = "your-facebook-page-account-id"
headers = {
"boring-api-key": API_KEY,
"Content-Type": "application/json"
}
response = requests.post(f"{API_URL}/api/fb/comment", headers=headers, json={
"account_id": ACCOUNT_ID,
"post_id": "123456789_987654321",
"message": "好文章!感謝分享。"
})
print(response.json())
取得留言
取得 Facebook 貼文的留言列表。
GET /api/fb/comments
請求標頭:
| 標頭 | 必填 | 說明 |
|---|---|---|
boring-api-key |
是 | 你的 API 金鑰 |
查詢參數:
| 參數 | 類型 | 必填 | 預設值 | 說明 |
|---|---|---|---|---|
account_id |
string | 是 | - | Facebook 粉絲專頁帳號 ID |
post_id |
string | 是 | - | Facebook 貼文 ID |
limit |
integer | 否 | 25 | 最多回傳筆數 |
範例:
curl "https://boring.aiagent-me.com/api/fb/comments?account_id=YOUR_ACCOUNT_ID&post_id=123456789_987654321&limit=10" \
-H "boring-api-key: boring_xxxxxxxxxxxxx"
成功回應:
{
"success": true,
"comments": [
{
"id": "123456789",
"message": "很棒的貼文!",
"from": {
"name": "王小明",
"id": "111222333"
},
"created_time": "2025-01-20T10:30:00+0000"
}
],
"post_id": "123456789_987654321",
"count": 1
}
錯誤回應
| 狀態碼 | 錯誤訊息 | 說明 |
|---|---|---|
| 400 | account_id is required |
缺少 account_id 參數 |
| 400 | post_id is required |
缺少 post_id 參數 |
| 400 | message is required |
缺少 message(僅 POST) |
| 401 | Authentication required |
缺少或無效的 API 金鑰 |
| 404 | Facebook account not found |
找不到帳號 ID 或非使用者所有 |
下一步
- Instagram 發佈:了解 Instagram 需求
- Threads 發佈:了解 Threads 需求
- API 參考:閱讀完整 API 文件
- 程式範例:查看更多程式範例