Quản lý Facebook Pages qua Graph API — đăng bài, ảnh, video, Reels, lên lịch, comment, moderation. Hỗ trợ nhiều page từ .env config.
Quản lý Facebook Pages: đăng bài (text/ảnh/video/Reels), lên lịch, comment, moderation — tất cả qua Graph API.
Bước 1: Lấy Short-lived User Token từ Graph API Explorer
pages_manage_posts, pages_read_engagement, pages_manage_engagement, pages_show_listBước 2: Đổi sang Long-lived User Token (60 ngày):
curl -s "https://graph.facebook.com/v21.0/oauth/access_token?\
grant_type=fb_exchange_token&\
client_id={APP_ID}&\
client_secret={APP_SECRET}&\
fb_exchange_token={SHORT_LIVED_USER_TOKEN}"
Bước 3: Lấy Page Token vĩnh viễn từ Long-lived User Token:
curl -s "https://graph.facebook.com/v21.0/{PAGE_ID}?fields=access_token&access_token={LONG_LIVED_USER_TOKEN}"
→ Page Token trả về sẽ không bao giờ hết hạn (expires_at: 0)
Verify token:
curl -s "https://graph.facebook.com/v21.0/debug_token?\
input_token={PAGE_TOKEN}&\
access_token={APP_ID}|{APP_SECRET}"
→ Kiểm tra expires_at: 0 = never expire ✅
Mỗi page cần một block trong .env:
APP: TenApp
App ID: 123456789
App Secret: abc123def456
Facebook page: Ten Page
Page_ID=123456789
page_access_token=EAAL...xyz
Có thể config nhiều page, mỗi page một block riêng.
curl -X POST "https://graph.facebook.com/v21.0/{PAGE_ID}/feed" \
-F "message=Nội dung bài viết" \
-F "access_token={PAGE_TOKEN}"
curl -X POST "https://graph.facebook.com/v21.0/{PAGE_ID}/photos" \
-F "source=@/path/to/image.jpg" \
-F "caption=Caption cho ảnh" \
-F "access_token={PAGE_TOKEN}"
# scheduled_publish_time = Unix timestamp (UTC)
curl -X POST "https://graph.facebook.com/v21.0/{PAGE_ID}/photos" \
-F "source=@/path/to/image.jpg" \
-F "caption=Caption cho ảnh" \
-F "published=false" \
-F "scheduled_publish_time={UNIX_TIMESTAMP}" \
-F "access_token={PAGE_TOKEN}"
curl -s "https://graph.facebook.com/v21.0/{PAGE_ID}/scheduled_posts?\
fields=id,message,scheduled_publish_time,is_published&\
access_token={PAGE_TOKEN}"
curl -X POST "https://graph.facebook.com/v21.0/{POST_ID}/comments" \
-F "message=Nội dung comment" \
-F "access_token={PAGE_TOKEN}"
curl -X DELETE "https://graph.facebook.com/v21.0/{POST_ID}?access_token={PAGE_TOKEN}"
curl -X POST "https://graph-video.facebook.com/v21.0/{PAGE_ID}/videos" \
-F "source=@/path/to/video.mp4" \
-F "description=Mô tả video" \
-F "access_token={PAGE_TOKEN}"
Hoặc dùng script: python3 scripts/post_video.py video.mp4 --page-id "PAGE_ID" --token "PAGE_TOKEN"
Xem chi tiết: references/reels-publishing.md (3 bước: init → upload → publish)
references/graph-api-overview.md — Base URLs, versioning, request patternsreferences/page-posting.md — Page posting workflowsreferences/reels-publishing.md — Reels publishing (3-90s vertical video)references/comments-moderation.md — Comment actions & moderationreferences/permissions-and-tokens.md — Token types & permissionsreferences/http-request-templates.md — HTTP request examplesv21.0)graph-video.facebook.com (khác với domain thường)rupload.facebook.com