I have problem with loading the images on creating Ad Creative
My code follows
public function createAdCreative($ad_set_id, $adName, $primaryText, $description, $websiteURL, $file)
{
try {
$ad_image = new AdImage(null, 'act_' . $this->ad_account_id);
$ad_image->{AdImageFields::FILENAME} = $file;
$ad_image->create();
$ad_creative = new AdCreative(null, 'act_' . $this->ad_account_id);
$ad_creative->setData([
AdCreativeFields::TITLE => $adName,
AdCreativeFields::BODY => $description,
AdCreativeFields::OBJECT_URL => $websiteURL,
AdCreativeFields::IMAGE_HASH => $ad_image->{AdImageFields::HASH},
AdCreativeFields::IMAGE_URL => env('APP_URL').'/uploads/'. basename($file), // basename($file),
AdCreativeFields::IMAGE_FILE => basename($file) // basename($file),
]);
$ad = new Ad(null, 'act_' . $this->ad_account_id);
$ad->setData([
AdFields::NAME => $adName,
AdFields::ADSET_ID => $ad_set_id,
AdFields::CREATIVE => $ad_creative
]);
$ad_res = $ad->create(array(
Ad::STATUS_PARAM_NAME => Ad::STATUS_PAUSED,
));
return $ad_creative->id;
} catch (RequestException $e) {
echo 'Exception ->: ' . $e->getMessage().PHP_EOL;
echo 'Error details: ' . json_encode($e->getErrorUserTitle()).PHP_EOL.PHP_EOL;
}
}
Hash image is created succesfuly
AdCreativeFields::IMAGE_HASH => $ad_image->{AdImageFields::HASH}
I tried with these 2 lines and without
AdCreativeFields::IMAGE_URL => env('APP_URL').'/uploads/'. basename($file), // basename($file),
AdCreativeFields::IMAGE_FILE => basename($file) // basename($file),
I followed the official doc here
https://developers.facebook.com/docs/marketing-api/reference/ad-image/v20.0
as a result I see an error “Missing Image”
How can I resolve this issue ?