Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 442
Stacy Thompson Avatar asked Aug 30 '17 19:08

Stacy Thompson


People also ask

What is API in Facebook ads?

The Marketing API is an HTTP-based API that you can use to query data, create and manage ads, and perform a wide variety of other tasks. The Marketing API can programmatically access Facebook's advertising platform and optimize your business operations.

What is an OAuthException error?

OAuthException: If you receive an OAuthException error, it means that Edgar doesn't have the correct permissions to access your Facebook accounts right now. The password may have been changed on Facebook or Facebook may have reset your security session.


1 Answers

$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.
like image 102
Prince Adeyemi Avatar answered Sep 19 '22 14:09

Prince Adeyemi