Facebook Ads API - 必需的父ID

时间:2016-10-25 23:23:29

标签: php facebook facebook-ads-api

尝试通过PHP API在Facebook上制作广告时出现错误。

Exception in AbstractCrudObject.php line 113: A parent ID is required.

问题是,我复制了https://developers.facebook.com/docs/marketing-api/guides/lead-ads/create/v2.8中的代码,并修改了它以符合我的需要。我对于缺少的东西感到困惑,因为到目前为止我在文档中找不到任何东西。其他人有同样的问题或了解如何解决它?

这是我的代码:

$link_data = new AdCreativeLinkData();
$link_data->setData([
    AdCreativeLinkDataFields::LINK => $creativeInfo->link,
    AdCreativeLinkDataFields::MESSAGE => $creativeInfo->message,
    AdCreativeLinkDataFields::IMAGE_HASH => $image->{AdImageFields::HASH}.PHP_EOL,
    AdCreativeLinkDataFields::CAPTION => $creativeInfo->caption,
    AdCreativeLinkDataFields::DESCRIPTION => $creativeInfo->description,
    AdCreativeLinkDataFields::CALL_TO_ACTION => [
        'type' => $creativeInfo->cta,
        'value' => [
            'lead_gen_form_id' => $creativeInfo->leadform,
        ],
    ],
]);

$story = new AdCreativeObjectStorySpec();
$story->setData([
    AdCreativeObjectStorySpecFields::PAGE_ID => $creativeInfo->page_id,
    AdCreativeObjectStorySpecFields::LINK_DATA => $link_data,
]);

$creative = new AdCreative();
$creative->setData([
    AdCreativeFields::OBJECT_STORY_SPEC => $story,
]);
$creative->create();

2 个答案:

答案 0 :(得分:0)

$adCreative = (new AdCreative(null))
  ->setParentId("act_{$this->pageId}");

答案 1 :(得分:-1)

当您实例化AdCreative对象时,您必须提供广告素材所在的广告帐户ID,如下所示:

$creative = new AdCreative(null, 'act_<AD_ACCOUNT_ID>'); //i.e. act_12424141412