我想用api创建一个创意。当我发布object_story_spec参数时,我收到此错误'Creative spec必须是关联数组(可选择json编码)'
这是我的json值,它是有效的。
{ "page_id" : "103830656322074", "link_data": { "call_to_action": {"type":"LEARN_MORE","value":{"link":"facebook.com/"}}, "caption": "Reklam #1", "name": "Reklam #1", "link": "facebook.com/", "message": "facebook.com/" }}
developers.facebook.com/docs/marketing-api/reference/ad-creative#Creating
答案 0 :(得分:0)
它应该是一样的东西。
object_story_spec={
"page_id": "<PAGE_ID>",
"video_data": {
"call_to_action": {"type":"LIKE_PAGE","value":{"page":"<PAGE_ID>"}},
"description": "try it out",
"image_url": "<THUMBNAIL_URL>",
"video_id": "<VIDEO_ID>"
}
}
Or
$object_story_spec = new ObjectStorySpec();
$object_story_spec->setData(array(
ObjectStorySpecFields::PAGE_ID => <PAGE_ID>,
ObjectStorySpecFields::LINK_DATA => <LINK_DATA>,
));
$creative = new AdCreative(null, 'ad_Acount_id');
$creative->setData(array(
AdCreativeFields::NAME => 'Sample Creative',
AdCreativeFields::OBJECT_STORY_SPEC => $object_story_spec,
));
答案 1 :(得分:0)
你应该在传递到下面的广告素材之前对$ object_story_spec进行网址添加。
no main manifest attribute, in Main.jar
$object_story_spec = urlencode($object_story_spec);
$creative = new AdCreative(null, 'ad_Acount_id');
$creative->setData(array(
AdCreativeFields::NAME => 'Sample Creative',
AdCreativeFields::OBJECT_STORY_SPEC => $object_story_spec,
));
答案 2 :(得分:0)
只需将定位字段转换为字符串,例如,如果您使用请求:
import requests
params = {
'name': 'My Ad Set',
'optimization_goal': 'LINK_CLICKS',
'billing_event': 'IMPRESSIONS',
'bid_amount': 2,
'daily_budget': 100,
'campaign_id': campaign_id,
"targeting": str({
"age_max": 65,
"age_min": 18,
"flexible_spec": [..]
}),
'start_time': datetime.now().strftime("%Y-%m-%dT%H:%M:%SZ"),
'status': 'PAUSED',
'access_token': access_token,
}
response = requests.post(
url=f'https://graph.facebook.com/v11.0/act_{ad_account_id}/adsets',
params=params
)