准备
- Facebook 开发者帐户:用于访问我们的开发者工具并创建 Facebook 应用程序。
- Facebook 应用程序:您构建的任何类型的 Facebook 广告功能的容器。
- 访问令牌:您可以获得系统用户访问令牌或长期过期的用户访问令牌。
- 权限:取决于您使用 API 的方式。
- 广告帐户:您需要一个广告帐户来管理对广告的访问、计费设置和支出限额。通过访问广告管理器内的广告帐户设置来查找您的帐户号码。
创建campaign
curl -X POST \
-F 'name="My campaign"' \
-F 'objective="OUTCOME_TRAFFIC"' \
-F 'status="PAUSED"' \
-F 'special_ad_categories=[]' \
-F 'access_token=<ACCESS_TOKEN>' \
https://graph.facebook.com/v<API_VERSION>/act_<AD_ACCOUNT_ID>/campaigns
创建adset
curl \
-F 'name=My Ad Set' \
-F 'optimization_goal=REACH' \
-F 'billing_event=IMPRESSIONS' \
-F 'bid_amount=2' \
-F 'daily_budget=1000' \
-F 'campaign_id=<CAMPAIGN_ID>' \
-F 'targeting={"geo_locations": {"countries":["US"]}, "interests": [{id: 6003139266461, "name": "Movies"}]}' \
-F 'start_time=2024-10-06T04:45:17+0000' \
-F 'status=PAUSED' \
-F 'access_token=<ACCESS_TOKEN>' \
https://graph.facebook.com/v<API_VERSION>/act_<AD_ACCOUNT_ID>/adsets
需要拉取定位 国家信息 兴趣 之类的信息,
创建adcreative
- Images and videos
- Title and description
- Links
- Call to Action buttons
先上传图片或视频上传素材库
curl \
-F 'filename=@<IMAGE_PATH>' \
-F 'access_token=<ACCESS_TOKEN>' \
https://graph.facebook.com/v<API_VERSION>/act_<AD_ACCOUNT_ID>/adimages
上传图片时设为base64
$data = [
'bytes' => base64_encode(file_get_contents('uploads/' . $file)),
'access_token' => env('ACCESS_TOKEN')
];
返回图片hash 值后 根据 值创建adcreative
curl -X POST \
-F 'name="Sample Creative"' \
-F 'object_story_spec={
"page_id": "<PAGE_ID>",
"link_data": {
"image_hash": "<IMAGE_HASH>",
"link": "https://facebook.com/<PAGE_ID>",
"message": "try it out"
}
}' \
-F 'degrees_of_freedom_spec={
"creative_features_spec": {
"standard_enhancements": {
"enroll_status": "OPT_IN"
}
}
}' \
-F 'access_token=<ACCESS_TOKEN>' \
https://graph.facebook.com/v<API_VERSION>/act_<AD_ACCOUNT_ID>/adcreatives
campaign 目标为 OUTCOME_APP_PROMOTION enroll_status 应为 OPT_OUT
创建ads
根据adcreative id 创建adset
curl -X POST \
-F 'name="My Ad"' \
-F 'adset_id="<AD_SET_ID>"' \
-F 'creative={
"creative_id": "<CREATIVE_ID>"
}' \
-F 'status="PAUSED"' \
-F 'access_token=<ACCESS_TOKEN>' \
https://graph.facebook.com/v<API_VERSION>/act_<AD_ACCOUNT_ID>/ads
文档地址:https://developers.facebook.com/docs/marketing-apis/get-started