Closed effetb closed 6 years ago
Finally i found why it was not working, I should not call the create method on the adcreative. Juste call the create method on the ad
$creative_id = null;
$link_data = new AdCreativeLinkData();
$link_data->setData(array(
AdCreativeLinkDataFields::MESSAGE => 'message',
AdCreativeLinkDataFields::LINK => 'https://example.org',
AdCreativeLinkDataFields::DESCRIPTION => 'description',
AdCreativeLinkDataFields::NAME => 'name',
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($creative_id);
$creative->setParentId($account_id);
$creative->setData(array(
AdCreativeFields::NAME => 'Sample Creative',
AdCreativeFields::OBJECT_STORY_SPEC => $object_story_spec,
));
//////////////////// AD ////////////////////////
$ad_id = null;
$ad = new Ad($ad_id);
$ad->setParentId($account_id);
$ad->setData(array(
AdFields::NAME => 'My Ad',
AdFields::ADSET_ID => $adset_id,
AdFields::CREATIVE => $creative,
));
try
{
$param = array(Ad::STATUS_PARAM_NAME => Ad::STATUS_PAUSED,);
$ad->create($param);
} catch (Exception $exception)
{
echo $exception->getMessage() . "\n";
echo $exception->getErrorUserMessage() . "\n";
echo $exception->getErrorUserTitle() . "\n";
}
echo 'ad_id: ' . $ad_id . "\n\n";
Small update for those who will have the same issue : you need to use the creative id and not the object itself when you create an ad.
Not working :
$ad_id = null;
$ad = new Ad($ad_id);
$ad->setParentId($account_id);
$ad->setData(array(
AdFields::NAME => 'My Ad',
AdFields::ADSET_ID => $adset_id,
AdFields::CREATIVE => $creative,
AdFields::STATUS => \FacebookAds\Object\Values\AdStatusValues::PAUSED
));
Change this line :
AdFields::CREATIVE => array('creative_id' => $creative_id),
Hello, I'm trying to create an ad to redirect facebook users to my website on click.
I have this error when creating the ad : You must select an object to promote that is related to your objective, for example a Page post, website URL, or app. Please add a promoted object and try again. Promoted Object Is Missing
The other steps are ok, I can create the ad creative.
Here is my code :
Can I have some help ? The examples are not working (ad creative can't be created). If someone has e working example of a website link ad creation it would be very nice.
Thank you