meta-ads-control
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseMeta Ads Control
Meta Ads 控制工具
Use this skill for Meta Marketing API work. Prefer the bundled script because it gives structured JSON output, dry-run protection, retries, pagination, batch support, async Insights jobs, targeting search, and asset upload.
此技能用于Meta Marketing API相关操作。优先使用配套脚本,因为它可提供结构化JSON输出、预演保护(dry-run)、重试机制、分页功能、批量支持、异步Insights任务、定向搜索以及素材上传能力。
Before you touch spend or delivery
涉及广告支出或投放前的注意事项
- Discover scope.
bash
python3 scripts/meta_ads.py accounts python3 scripts/meta_ads.py account - Confirm the intended ad account, currency, timezone, and writable objects.
- For any change that can spend money, change delivery, or alter tracking:
- prepare a short plan,
- run ,
--dry-run - show the exact objects and fields to be changed,
- wait for explicit user approval,
- then rerun with .
--confirm
- Default new campaigns, ad sets, and ads to unless the user explicitly asks to go live immediately.
PAUSED - After any write, do a read-after-write verification with ,
get, orlist.request GET
- 明确操作范围。
bash
python3 scripts/meta_ads.py accounts python3 scripts/meta_ads.py account - 确认目标广告账户、货币、时区以及可编辑对象。
- 对于任何可能产生支出、影响投放或更改追踪设置的操作:
- 准备简短计划,
- 运行预演,
--dry-run - 展示将被修改的具体对象和字段,
- 等待用户明确批准,
- 然后使用参数重新运行。
--confirm
- 默认情况下,新建的广告系列、广告组和广告状态设为,除非用户明确要求立即上线。
PAUSED - 任何写入操作完成后,使用、
get或list进行写后读取验证。request GET
Authentication and environment
身份验证与环境配置
The script reads:
- — required for live API calls
META_ACCESS_TOKEN - — optional default account, with or without
META_AD_ACCOUNT_IDact_ - — defaults to
META_API_VERSIONv25.0 - — defaults to
META_GRAPH_BASEhttps://graph.facebook.com
If is missing, help the user set it up first instead of guessing or fabricating API responses.
META_ACCESS_TOKENOpenClaw users can inject these values through skill config. See OpenClaw notes.
脚本会读取以下环境变量:
- — 实时API调用必填
META_ACCESS_TOKEN - — 可选的默认账户ID,可带或不带
META_AD_ACCOUNT_ID前缀act_ - — 默认值为
META_API_VERSIONv25.0 - — 默认值为
META_GRAPH_BASEhttps://graph.facebook.com
如果缺少,请先帮助用户完成设置,而非猜测或伪造API响应。
META_ACCESS_TOKENOpenClaw用户可通过技能配置注入这些值。详情请查看OpenClaw说明文档。
Fast path by task
按任务快速操作指南
1) Audit or diagnose an account
1) 账户审计或诊断
Start with the smallest read that answers the question.
bash
python3 scripts/meta_ads.py account --fields id,name,account_status,currency,timezone_name,amount_spent,spend_cap
python3 scripts/meta_ads.py list campaigns --fields id,name,objective,status,effective_status,daily_budget,lifetime_budget
python3 scripts/meta_ads.py list adsets --fields id,name,campaign_id,status,effective_status,daily_budget,lifetime_budget,optimization_goal,bid_strategy
python3 scripts/meta_ads.py list ads --fields id,name,adset_id,campaign_id,status,effective_status,creativeUse when you need several small reads at once. Use minimal field sets first.
batch从能解答问题的最小范围读取操作开始。
bash
python3 scripts/meta_ads.py account --fields id,name,account_status,currency,timezone_name,amount_spent,spend_cap
python3 scripts/meta_ads.py list campaigns --fields id,name,objective,status,effective_status,daily_budget,lifetime_budget
python3 scripts/meta_ads.py list adsets --fields id,name,campaign_id,status,effective_status,daily_budget,lifetime_budget,optimization_goal,bid_strategy
python3 scripts/meta_ads.py list ads --fields id,name,adset_id,campaign_id,status,effective_status,creative当需要同时执行多个小型读取操作时,使用命令。优先使用最小字段集。
batch2) Performance reporting
2) 绩效报告
Use . Start with a narrow level and date window. For large windows, many fields, or breakdowns, use .
insights--asyncbash
python3 scripts/meta_ads.py insights act_123 --level campaign --date-preset last_7d
python3 scripts/meta_ads.py insights act_123 --level ad --fields ad_id,ad_name,spend,impressions,clicks,ctr,cpc,actions,action_values,purchase_roas --date-preset last_30d --async --fetch-allIf the user asks for conversions or ROAS, include and . If the user asks for demographic or placement splits, use . If they ask for action-level splits, include and use .
actionsaction_values--breakdownsactions--action-breakdowns使用命令。从较窄的层级和日期范围开始。对于大范围日期、多字段或拆分维度的报告,使用参数。
insights--asyncbash
python3 scripts/meta_ads.py insights act_123 --level campaign --date-preset last_7d
python3 scripts/meta_ads.py insights act_123 --level ad --fields ad_id,ad_name,spend,impressions,clicks,ctr,cpc,actions,action_values,purchase_roas --date-preset last_30d --async --fetch-all如果用户询问转化或ROAS相关内容,请包含和字段。如果用户询问人群统计或版位拆分,请使用参数。如果用户询问操作层级拆分,请包含字段并使用参数。
actionsaction_values--breakdownsactions--action-breakdowns3) Pause, resume, or archive objects
3) 暂停、恢复或归档对象
Prefer for single-object changes.
set-statusbash
python3 scripts/meta_ads.py set-status 120000000000000 PAUSED --dry-run
python3 scripts/meta_ads.py set-status 120000000000000 PAUSED --confirmFor bulk operations, create a JSON batch file and use after approval.
batch单个对象状态变更优先使用命令。
set-statusbash
python3 scripts/meta_ads.py set-status 120000000000000 PAUSED --dry-run
python3 scripts/meta_ads.py set-status 120000000000000 PAUSED --confirm对于批量操作,创建JSON批量文件并在获得批准后使用命令。
batch4) Create or update campaign structure
4) 创建或更新广告系列结构
Create in order:
- campaign
- ad set
- creative
- ad
Use JSON payload files for any nested params. Start from templates in .
assets/bash
python3 scripts/meta_ads.py create campaign --params-file assets/campaign-create.json --dry-run
python3 scripts/meta_ads.py create campaign --params-file work/campaign.json --confirm
python3 scripts/meta_ads.py create adset --params-file work/adset.json --dry-run
python3 scripts/meta_ads.py create adset --params-file work/adset.json --confirm
python3 scripts/meta_ads.py create adcreative --params-file work/adcreative.json --dry-run
python3 scripts/meta_ads.py create adcreative --params-file work/adcreative.json --confirm
python3 scripts/meta_ads.py create ad --params-file work/ad.json --dry-run
python3 scripts/meta_ads.py create ad --params-file work/ad.json --confirmIf assets are local files, upload them first with .
upload按以下顺序创建:
- 广告系列(campaign)
- 广告组(ad set)
- 创意(creative)
- 广告(ad)
任何嵌套参数使用JSON负载文件。可从目录下的模板开始。
assets/bash
python3 scripts/meta_ads.py create campaign --params-file assets/campaign-create.json --dry-run
python3 scripts/meta_ads.py create campaign --params-file work/campaign.json --confirm
python3 scripts/meta_ads.py create adset --params-file work/adset.json --dry-run
python3 scripts/meta_ads.py create adset --params-file work/adset.json --confirm
python3 scripts/meta_ads.py create adcreative --params-file work/adcreative.json --dry-run
python3 scripts/meta_ads.py create adcreative --params-file work/adcreative.json --confirm
python3 scripts/meta_ads.py create ad --params-file work/ad.json --dry-run
python3 scripts/meta_ads.py create ad --params-file work/ad.json --confirm如果素材是本地文件,请先使用命令上传。
upload5) Targeting discovery
5) 定向设置查询
Never invent targeting IDs. Resolve them with targeting search first.
bash
python3 scripts/meta_ads.py targeting-search --type adinterest --q "running"
python3 scripts/meta_ads.py targeting-search --type adgeolocation --q "Munich"Then place the returned IDs and descriptors into the ad set spec.
targeting切勿自行编造定向ID。先通过定向搜索获取正确ID。
bash
python3 scripts/meta_ads.py targeting-search --type adinterest --q "running"
python3 scripts/meta_ads.py targeting-search --type adgeolocation --q "Munich"然后将返回的ID和描述信息填入广告组的参数中。
targeting6) Unsupported or niche endpoints
6) 不支持或小众的API端点
Use the low-level subcommand.
requestbash
python3 scripts/meta_ads.py request GET /act_123/reachestimate --set targeting_spec=@work/targeting.json
python3 scripts/meta_ads.py request GET /120000000000000/previews --set ad_format=DESKTOP_FEED_STANDARDFor nested values, prefer or values over many inline s.
--params-file@file.json--set使用底层的子命令。
requestbash
python3 scripts/meta_ads.py request GET /act_123/reachestimate --set targeting_spec=@work/targeting.json
python3 scripts/meta_ads.py request GET /120000000000000/previews --set ad_format=DESKTOP_FEED_STANDARD对于嵌套值,优先使用或参数,而非多个内联参数。
--params-file@file.json--setScript reference
脚本参考
Main entry point
主入口
bash
python3 scripts/meta_ads.py --helpbash
python3 scripts/meta_ads.py --helpMost useful subcommands
最常用的子命令
- — list accessible ad accounts from the token
accounts - — read the default or provided account
account - — list campaigns, adsets, ads, creatives, audiences, assets, pixels, and more
list - — read a node or node edge
get - — create campaign, adset, adcreative, ad, customaudience, or any supported account edge
create - — update a node by ID
update - — convenience wrapper for
set-statusstatus - — sync or async reporting
insights - — resolve targeting descriptors
targeting-search - — upload to
uploadoradimagesadvideos - — send Graph batch requests
batch - — low-level escape hatch for any Graph path
request
- — 列出令牌可访问的广告账户
accounts - — 读取默认或指定的账户信息
account - — 列出广告系列、广告组、广告、创意、受众、素材、像素等内容
list - — 读取节点或节点边缘信息
get - — 创建广告系列、广告组、广告创意、广告、自定义受众或任何支持的账户边缘对象
create - — 通过ID更新节点信息
update - —
set-status操作的便捷封装命令status - — 同步或异步报告生成
insights - — 解析定向描述信息
targeting-search - — 上传素材至
upload或adimagesadvideos - — 发送Graph批量请求
batch - — 针对任何Graph路径的底层应急命令
request
Rules for good agent behaviour
智能体操作规范
- Read before write.
- Use the smallest field set that answers the question.
- Prefer JSON payload files for nested data.
- Use only when the user actually needs all pages.
--fetch-all - Use for heavy Insights jobs.
--async - Pause on repeated 613 or 80004 rate-limit errors; reduce scope or add time between retries.
- Prefer or
PAUSEDover destructive delete operations.ARCHIVED - Report money in both raw API units and human units when relevant. Budgets are usually in the smallest currency denomination.
- When writing budgets, verify account currency and timezone first.
- After any mutation, verify the live state with a follow-up read.
- If the request touches housing, employment, credit, social issues, elections, or politics, check API guide for special-category cautions before proceeding.
- 先读取后写入。
- 使用能解答问题的最小字段集。
- 嵌套数据优先使用JSON负载文件。
- 仅当用户确实需要所有页面数据时才使用参数。
--fetch-all - 大型Insights任务使用参数。
--async - 遇到重复的613或80004限流错误时暂停操作;缩小范围或增加重试间隔。
- 优先使用或
PAUSED状态,而非破坏性删除操作。ARCHIVED - 相关情况下,同时以原始API单位和人类可读单位报告金额。预算通常使用最小货币单位。
- 设置预算时,先验证账户货币和时区。
- 任何变更操作后,通过后续读取验证实时状态。
- 如果请求涉及住房、就业、信贷、社会问题、选举或政治内容,操作前请查看API指南中的特殊类别注意事项。
Examples
示例
Quick 7-day account snapshot
快速生成7天账户快照
bash
python3 scripts/meta_ads.py batch --batch-file assets/batch-read-example.json
python3 scripts/meta_ads.py insights act_123 --level campaign --date-preset last_7d --fields campaign_id,campaign_name,spend,impressions,clicks,ctr,cpc,actions,action_values,purchase_roasbash
python3 scripts/meta_ads.py batch --batch-file assets/batch-read-example.json
python3 scripts/meta_ads.py insights act_123 --level campaign --date-preset last_7d --fields campaign_id,campaign_name,spend,impressions,clicks,ctr,cpc,actions,action_values,purchase_roasIncrease a budget safely
安全提升预算
- Inspect the current ad set.
- Prepare an update payload with the new budget.
- Dry-run it.
- Ask for confirmation.
- Apply and verify.
bash
python3 scripts/meta_ads.py get 120000000000000 --fields id,name,status,effective_status,daily_budget,lifetime_budget
python3 scripts/meta_ads.py update 120000000000000 --params-file work/adset-budget.json --dry-run
python3 scripts/meta_ads.py update 120000000000000 --params-file work/adset-budget.json --confirm
python3 scripts/meta_ads.py get 120000000000000 --fields id,name,daily_budget,lifetime_budget,updated_time- 检查当前广告组信息。
- 准备包含新预算的更新负载文件。
- 执行预演。
- 请求用户确认。
- 应用变更并验证。
bash
python3 scripts/meta_ads.py get 120000000000000 --fields id,name,status,effective_status,daily_budget,lifetime_budget
python3 scripts/meta_ads.py update 120000000000000 --params-file work/adset-budget.json --dry-run
python3 scripts/meta_ads.py update 120000000000000 --params-file work/adset-budget.json --confirm
python3 scripts/meta_ads.py get 120000000000000 --fields id,name,daily_budget,lifetime_budget,updated_timeUpload an image and build a link ad
上传图片并创建链接广告
bash
python3 scripts/meta_ads.py upload adimages --file creative.jpg --confirmbash
python3 scripts/meta_ads.py upload adimages --file creative.jpg --confirmPut the returned image_hash into work/adcreative.json
将返回的image_hash填入work/adcreative.json
python3 scripts/meta_ads.py create adcreative --params-file work/adcreative.json --confirm
python3 scripts/meta_ads.py create ad --params-file work/ad.json --confirm
undefinedpython3 scripts/meta_ads.py create adcreative --params-file work/adcreative.json --confirm
python3 scripts/meta_ads.py create ad --params-file work/ad.json --confirm
undefinedReferences
参考资料
- API guide
- Field sets and reporting defaults
- Workflow playbook
- Troubleshooting
- OpenClaw notes
- Asset templates in
assets/ - Example evals in
evals/evals.json
- API指南
- 字段集与报告默认值
- 工作流手册
- 故障排查
- OpenClaw说明文档
- 目录下的素材模板
assets/ - 中的示例评估
evals/evals.json