简体   繁体   中英

Facebook Ad API Error

I am getting error while creating Creative using the FB Ads PHP SDK

$parent_id as a parameter of constructor is being deprecated, please try not to use this in new code.

The code was working before the 2.9 and 2.10 update.

The Code I am using to create Creative is:

    $link_data = new AdCreativeLinkData();
$link_data->setData(array(
  AdCreativeLinkDataFields::MESSAGE => 'Product Description',
  AdCreativeLinkDataFields::LINK => $url_of_website,
  AdCreativeLinkDataFields::IMAGE_HASH => $image->hash,
  AdCreativeLinkDataFields::DESCRIPTION => 'Link Description',
  AdCreativeLinkDataFields::CALL_TO_ACTION => array(
    'type' => AdCreativeCallToActionTypeValues::LEARN_MORE,
    'value' => array(
      'link_title' => 'View Similar Products Now!',
      'lead_gen_form_id' =>  $form_id,
    ),
  ),
));

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

$creative = new AdCreative(null, $account_id);
$creative->setData(array(
  AdCreativeFields::NAME => $nm,
  AdCreativeFields::OBJECT_STORY_SPEC => $story,
  AdCreativeFields::URL_TAGS => 'product=' . $p_id,
));

$creative->create();

I do not see any parent id in this statement. Please help

$parent_id is deprecated

The issue was reported on facebook github with issue# 314

Response from Facebook Developer

"We are depreciating creation with parent_id. We are seeing multiple endpoints that can create the same type of object. We do not have good ways to decide which one we should use if you are creating new object with parent_id. Moving forward, please instantiate the parent object with the parent_id and call create_XXX function to create the object you want."

Sample Code:

use FacebookAds\Object\AdCreative;
use FacebookAds\Object\AdCreativeLinkData;
use FacebookAds\Object\Fields\AdCreativeLinkDataFields;
use FacebookAds\Object\AdCreativeObjectStorySpec;
use FacebookAds\Object\Fields\AdCreativeObjectStorySpecFields;
use FacebookAds\Object\Fields\AdCreativeFields;

$link_data = new AdCreativeLinkData();
$link_data->setData(array(
  AdCreativeLinkDataFields::MESSAGE => 'try it out',
  AdCreativeLinkDataFields::LINK => '<URL>',
  AdCreativeLinkDataFields::IMAGE_HASH => '<IMAGE_HASH>',
));

$object_story_spec = new AdCreativeObjectStorySpec();
$object_story_spec->setData(array(
  AdCreativeObjectStorySpecFields::PAGE_ID => <PAGE_ID>,
  AdCreativeObjectStorySpecFields::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();
Hope this helps.

Use setParentId($parrent_id) .

Sample code:

$product_catalog = new ProductCatalog();
$product_catalog->setParentId($parrent_id);
$product_catalog->setData(
            [
                ProductCatalogFields::NAME => "Testjon Autojon Catalog",
                ProductCatalogFields::VERTICAL => "vehicles",
            ]
);
$product_catalog->create();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM