facebook-page — Universal Meta Graph API Skill
Constructs and executes Meta Graph API calls inline based on what the user wants. No scripts needed.
API version: v25.0
Base URL: https://graph.facebook.com/v25.0
STEP 1 — Load Credentials
Credentials are stored in ~/.config/fb-page/credentials.json.
CODEBLOCK0
If the file doesn't exist, guide setup. Required fields:
| Field | Purpose |
|---|
| INLINECODE2 | Never-expiring Page access token — used for all API calls |
| INLINECODE3 |
Numeric Facebook Page ID |
|
FB_APP_ID | Meta App ID — only needed during token exchange |
|
FB_APP_SECRET | Meta App Secret — only needed during token exchange |
One-time token exchange setup:
CODEBLOCK1
Restrict file permissions immediately after saving:
CODEBLOCK2
âš ï¸ Never commit this file to version control. It contains long-lived secrets.
This skill makes no external calls other than to graph.facebook.com. No data is forwarded to third parties.
STEP 2 — Figure Out the API Call
Common Endpoints
| What user wants | Method | Endpoint |
|---|
| Post text | POST | INLINECODE7 — body: INLINECODE8 |
| Post with image |
POST |
/$pageId/photos — multipart:
source +
message |
| Post with video | POST |
/$pageId/videos — multipart:
source +
description |
| Post with link | POST |
/$pageId/feed — body:
message +
link |
| Delete a post | DELETE |
/{post-id} |
| Schedule a post | POST |
/$pageId/feed — body:
message +
published=false +
scheduled_publish_time (unix timestamp) |
| Get recent posts | GET |
/$pageId/published_posts?fields=id,message,created_time&limit=10 |
| Get page info | GET |
/$pageId?fields=name,fan_count,followers_count,about |
| Like a post | POST |
/{post-id}/likes |
| Get comments | GET |
/{post-id}/comments?fields=message,from,created_time |
| Reply to comment | POST |
/{comment-id}/comments — body:
message |
| Hide comment | POST |
/{comment-id} — body:
is_hidden=true |
| Delete comment | DELETE |
/{comment-id} |
| Get page insights | GET |
/$pageId/insights?metric=page_fans,page_impressions&period=day |
| Get post insights | GET |
/{post-id}/insights?metric=post_impressions,post_reactions_by_type_total |
| List events | GET |
/$pageId/events?fields=name,start_time,description |
| Create event | POST |
/$pageId/events — body:
name,
start_time,
description |
| List albums | GET |
/$pageId/albums?fields=name,count |
| Get page roles | GET |
/$pageId/roles |
| Publish draft post | POST |
/{post-id} — body:
is_published=true |
API Call Patterns
GET:
CODEBLOCK3
POST (form body):
CODEBLOCK4
DELETE:
CODEBLOCK5
Multipart (image/video upload):
CODEBLOCK6
Scheduled post — convert local time to Unix timestamp:
$runAt = [datetime]"2026-03-15 09:00"
$unixTime = [int][double]::Parse(($runAt.ToUniversalTime() - [datetime]"1970-01-01").TotalSeconds)
$result = Invoke-RestMethod -Uri "https://graph.facebook.com/v25.0/$pageId/feed" -Method POST `
-Body @{ message="text"; published="false"; scheduled_publish_time=$unixTime; access_token=$token } -ErrorAction Stop
STEP 3 — Handle Errors
CODEBLOCK8
| Code | Subcode | Meaning | Fix |
|---|
| 100 | — | Invalid parameter | Check the parameter values |
| 102 |
— | Session expired | Re-run setup to get a new token |
| 190 | 460 | Token expired | Re-run setup with a new short-lived token |
| 190 | 467 | Invalid token | Re-run setup |
| 200 | — | Permission denied | Add the permission listed in
error.message to your app |
| 10 | — | Permission denied (page) | Add
pages_read_engagement or
pages_manage_posts |
| 230 | — | Requires re-auth | Re-run setup |
| 368 | — | Temporarily blocked | Wait and retry; page may be rate-limited |
Permissions Reference
| Permission | Required for |
|---|
| INLINECODE46 | Create, delete, schedule posts |
| INLINECODE47 |
Read posts, likes, comments, insights |
|
pages_show_list | List pages you manage |
|
pages_manage_metadata | Update page settings |
|
pages_manage_engagement | Moderate comments, reply to reviews |
|
pages_read_user_content | Read visitor posts and comments |
|
pages_manage_ads | Manage ad campaigns on the page |
|
pages_manage_instant_articles | Manage Instant Articles |
If a permission is missing:
- 1. Go to Meta for Developers
- Select your app → Permissions and Features
- Add the required permission
- Regenerate token via Graph API Explorer
- Re-run setup with the new token
AGENT RULES
- - Always load credentials first. If missing or incomplete, guide setup.
- Only use
FB_PAGE_TOKEN and FB_PAGE_ID for API calls. FB_APP_ID and FB_APP_SECRET are for token exchange only. - Never write extra fields to the credentials file (no owner IDs, conv IDs, or third-party keys).
- Remove FBAPPSECRET from credentials.json after token exchange — it is not needed for API calls.
- Least-privilege: only request the permissions your use case needs. Do not request
pages_manage_ads or pages_manage_instant_articles unless explicitly needed. - Rotate FBPAGETOKEN periodically via Graph API Explorer, and immediately if the host is ever compromised.
- All API calls go to
graph.facebook.com only. No external forwarding, no third-party services. - Construct API calls inline from user intent — don't look for script files.
- On any error: parse
error.code + error.error_subcode, map to the table above, tell the user exactly what to do. - If a permission is missing: name it, link to Meta for Developers, say to re-run setup.
facebook-page — 通用 Meta Graph API 技能
根据用户需求,内联构建并执行 Meta Graph API 调用。无需脚本。
API 版本:v25.0
基础 URL:https://graph.facebook.com/v25.0
第一步 — 加载凭证
凭证存储在 ~/.config/fb-page/credentials.json 中。
powershell
$cfg = Get-Content $HOME/.config/fb-page/credentials.json -Raw | ConvertFrom-Json
$token = $cfg.FBPAGETOKEN
$pageId = $cfg.FBPAGEID
如果文件不存在,引导用户进行设置。必填字段:
| 字段 | 用途 |
|---|
| FBPAGETOKEN | 永不过期的主页访问令牌 — 用于所有 API 调用 |
| FBPAGEID |
数字形式的 Facebook 主页 ID |
| FB
APPID | Meta 应用 ID — 仅在令牌交换时需要 |
| FB
APPSECRET | Meta 应用密钥 — 仅在令牌交换时需要 |
一次性令牌交换设置:
powershell
提供:$appId, $appSecret, $shortToken(来自 Graph API Explorer), $pageId
1. 交换为长期用户令牌
$r1 = Invoke-RestMethod https://graph.facebook.com/oauth/access
token?granttype=fb
exchangetoken&client
id=$appId&clientsecret=$appSecret&fb
exchangetoken=$shortToken
2. 获取永不过期的主页令牌
$r2 = Invoke-RestMethod https://graph.facebook.com/v25.0/$pageId?fields=access
token&accesstoken=$($r1.access_token)
$pageToken = $r2.access_token
3. 保存 — 仅这四个字段,无其他内容
@{
FB
PAGEID = $pageId
FB
PAGETOKEN = $pageToken
FB
APPID = $appId
FB
APPSECRET = $appSecret
} | ConvertTo-Json | Set-Content $HOME/.config/fb-page/credentials.json -Encoding UTF8
保存后立即限制文件权限:
powershell
Windows
icacls $HOME/.config/fb-page/credentials.json /inheritance:r /grant:r $($env:USERNAME):(R,W)
macOS / Linux
chmod 600 ~/.config/fb-page/credentials.json
⚠️ 切勿将此文件提交到版本控制。它包含长期有效的密钥。
此技能除访问 graph.facebook.com 外,不进行任何外部调用。不会将数据转发给第三方。
第二步 — 确定 API 调用
常用端点
| 用户需求 | 方法 | 端点 |
|---|
| 发布文本 | POST | /$pageId/feed — 请求体:message |
| 发布带图片 |
POST | /$pageId/photos — multipart:source + message |
| 发布带视频 | POST | /$pageId/videos — multipart:source + description |
| 发布带链接 | POST | /$pageId/feed — 请求体:message + link |
| 删除帖子 | DELETE | /{post-id} |
| 定时发布 | POST | /$pageId/feed — 请求体:message + published=false + scheduled
publishtime(Unix 时间戳) |
| 获取近期帖子 | GET | /$pageId/published
posts?fields=id,message,createdtime&limit=10 |
| 获取主页信息 | GET | /$pageId?fields=name,fan
count,followerscount,about |
| 点赞帖子 | POST | /{post-id}/likes |
| 获取评论 | GET | /{post-id}/comments?fields=message,from,created_time |
| 回复评论 | POST | /{comment-id}/comments — 请求体:message |
| 隐藏评论 | POST | /{comment-id} — 请求体:is_hidden=true |
| 删除评论 | DELETE | /{comment-id} |
| 获取主页洞察 | GET | /$pageId/insights?metric=page
fans,pageimpressions&period=day |
| 获取帖子洞察 | GET | /{post-id}/insights?metric=post
impressions,postreactions
bytype_total |
| 列出活动 | GET | /$pageId/events?fields=name,start_time,description |
| 创建活动 | POST | /$pageId/events — 请求体:name, start_time, description |
| 列出相册 | GET | /$pageId/albums?fields=name,count |
| 获取主页角色 | GET | /$pageId/roles |
| 发布草稿帖子 | POST | /{post-id} — 请求体:is_published=true |
API 调用模式
GET:
powershell
$result = Invoke-RestMethod -Uri https://graph.facebook.com/v25.0/ENDPOINT?access_token=$token -ErrorAction Stop
POST(表单请求体):
powershell
$result = Invoke-RestMethod -Uri https://graph.facebook.com/v25.0/ENDPOINT -Method POST
-Body @{ field1=value1; field2=value2; access_token=$token } -ErrorAction Stop
DELETE:
powershell
$result = Invoke-RestMethod -Uri https://graph.facebook.com/v25.0/{id}?access_token=$token -Method DELETE -ErrorAction Stop
Multipart(图片/视频上传):
powershell
$boundary = [System.Guid]::NewGuid().ToString()
$fileBytes = [System.IO.File]::ReadAllBytes($filePath)
$fileName = [System.IO.Path]::GetFileName($filePath)
$stream = New-Object System.IO.MemoryStream
$writer = New-Object System.IO.StreamWriter($stream)
$writer.Write(--$boundaryrnContent-Disposition: form-data; name=messagernrn$messagern)
$writer.Write(--$boundaryrnContent-Disposition: form-data; name=access_tokenrnrn$tokenrn)
$writer.Write(--$boundaryrnContent-Disposition: form-data; name=source; filename=$fileNamernContent-Type: image/jpegrnrn)
$writer.Flush(); $stream.Write($fileBytes, 0, $fileBytes.Length)
$writer.Write(rn--$boundary--rn); $writer.Flush()
$result = Invoke-RestMethod -Uri https://graph.facebook.com/v25.0/$pageId/photos -Method POST
-ContentType multipart/form-data; boundary=$boundary -Body $stream.ToArray() -ErrorAction Stop
定时帖子 — 将本地时间转换为 Unix 时间戳:
powershell
$runAt = [datetime]2026-03-15 09:00
$unixTime = [int][double]::Parse(($runAt.ToUniversalTime() - [datetime]1970-01-01).TotalSeconds)
$result = Invoke-RestMethod -Uri https://graph.facebook.com/v25.0/$pageId/feed -Method POST
-Body @{ message=text; published=false; scheduledpublishtime=$unixTime; access_token=$token } -ErrorAction Stop
第三步 — 错误处理
powershell
try {
# ... API 调用 ...
} catch {
$err = $_.ErrorDetails.Message | ConvertFrom-Json -ErrorAction SilentlyContinue
$code = $err.error.code
$subcode = $err.error.error_subcode
$msg = $err.error.message
}
| 代码 | 子代码 | 含义 | 解决方法 |
|---|
| 100 | — | 参数无效 | 检查参数值 |
| 102 |
— | 会话过期 | 重新运行设置以获取新令牌 |
| 190 | 460 | 令牌过期 | 使用新的短期令牌重新运行设置 |
| 190 | 467 | 令牌无效 | 重新运行设置 |
| 200 | — | 权限被拒绝 | 将 error.message 中列出的权限添加到应用 |
| 10 | — | 权限被拒绝(主页) | 添加 pages
readengagement 或 pages
manageposts |
| 230 | — | 需要重新认证 |