我正在使用Facebook Marketing API构建一些广告自动化平台。现在我正在尝试执行广告制作。最后一步是设置负责广告代表的广告素材对象。这是我的代码:
public function createCreative() {
$link_data = new LinkData();
$link_data->setData(array(
LinkDataFields::MESSAGE => 'try it out',
LinkDataFields::LINK => 'http://nomer.beeline.kz/ru/Numbers?utm_source=fb&utm_medium=cpc&utm_campaign=010681',
LinkDataFields::CAPTION => 'My caption',
LinkDataFields::IMAGE_HASH => 'aaf5226d9a8121e0dd30670565f00005',
));
$object_story_spec = new ObjectStorySpec();
$object_story_spec->setData(array(
ObjectStorySpecFields::LINK_DATA => $link_data,
ObjectStorySpecFields::PAGE_ID => 178928252129734
));
$creative = new AdCreative(null, 'act_'.$this->account_id);
$creative->setData(array(
AdCreativeFields::NAME => 'Sample Creative',
AdCreativeFields::OBJECT_STORY_SPEC => $object_story_spec,
));
$creative->create();
执行后我收到了这个错误:
FacebookAds\Http\Exception\RequestException Invalid parameter
我认为它是PAGE_ID
参数,实际上我不知道应该在那里。我粘贴了公开页面的ID
,其中包含所有广告操作。
有什么想法吗?
答案 0 :(得分:0)
PAGE_ID
参数是正确的。实际上问题出在$link_data
,您遗漏了CALL_TO_ACTION
$link_data = new LinkData();
$link_data->setData(array(
LinkDataFields::MESSAGE => 'try it out',
LinkDataFields::LINK => '<URL>',
LinkDataFields::CAPTION => 'My caption',
LinkDataFields::CALL_TO_ACTION => array(
'type' => CallToActionTypes::SIGN_UP,
'value' => array(
'link' => '<URL>',
'link_caption' => 'Sign up!',
),
),
));
$object_story_spec = new ObjectStorySpec();
$object_story_spec->setData(array(
ObjectStorySpecFields::PAGE_ID => <PAGE_ID>,
ObjectStorySpecFields::LINK_DATA => $link_data,
));
$creative = new AdCreative(null, 'act_<AD_ACCOUNT_ID>');
$creative->setData(array(
AdCreativeFields::NAME => 'Sample Creative',
AdCreativeFields::OBJECT_STORY_SPEC => $object_story_spec,
));
$creative->create();
Facebook营销API文档Ad Creative Link Data