hi everyone,
I attempt to generate a complete adCampaign on the Facebook API Marketing since 1 week right now.
I'm trying to create an ad without this error (nothing more is precised... ...).
I've searched for a response but nothing was conclusive for me.
However, I can create campaign, adSet, adCreative without any issues.
I'm sure about all IDs.
Maybe a previous parameter block the process? But , definitely, i don't see which one.
It might be in the targeting parameters, or adCreative params.
The App used is in the last update, same for SDK.
My function for ad creation:
public function createAd()
{
$fields = array(
AdFields::NAME => 'My first Ad',
AdFields::ADSET_ID => '2XXXXXXXXXXXXXX7',
AdFields::CREATIVE => array(
'creative_id' => '2XXXXXXXXXXXXXXX7',
),
AdFields::STATUS => Ad::STATUS_PAUSED,
);
$ad = new Ad(null, 'act_1XXXXXXXXXXXXXX3');
$ad->create($fields);
}
Here is the complete code used (initially, each step are in a function associate to a controller function):
/* connection to the api */
$object = Api::init(
'XXXXXXXXXXXXX', // App ID
'XXXXXXXXXXXXXXXXXXXXXXXXXX' //App Secret,
'X' // Your user access token
);
$api = Api::instance();
/* adCampaign creation */
$campaign = new Campaign(null, 'act_1XXXXXXXXXXXXXX3');
$campaign->setData(array(
CampaignFields::NAME => 'My First Campaign',
CampaignFields::OBJECTIVE => 'LINK_CLICKS',
));
$campaign->validate()->create(array(
Campaign::STATUS_PARAM_NAME => Campaign::STATUS_PAUSED,
));
echo "Campaign ID:" . $campaign->id . "\n";
/* Targeting settings */
$targeting = new Targeting();
$targeting->setData(array(
TargetingFields::GEO_LOCATIONS => array(
'countries' => array('JP'),
'regions' => array(array('key' => '3886')),
'cities' => array(
array(
'key' => '2420605',
'radius' => 10,
'distance_unit' => 'mile',
),
),
),
));
/* AdSet Creation */
$targeting = $this->paramTargeting();
$adset = new AdSet(null, 'act_1XXXXXXXXXXXXXXX3');
$adset->setData(array(
AdSetFields::NAME => 'My First AdSet',
AdSetFields::CAMPAIGN_ID => '2XXXXXXXXXXXXXXX7',
AdSetFields::DAILY_BUDGET => '150',
AdSetFields::TARGETING => $targeting,
AdSetFields::OPTIMIZATION_GOAL => AdSetOptimizationGoalValues::REACH,
AdSetFields::BILLING_EVENT => AdSetBillingEventValues::IMPRESSIONS,
AdSetFields::BID_AMOUNT => 100,
AdSetFields::START_TIME =>
(new \DateTime("+1 week"))->format(\DateTime::ISO8601),
AdSetFields::END_TIME =>
(new \DateTime("+2 week"))->format(\DateTime::ISO8601),
));
$adset->validate()->create(array(
AdSet::STATUS_PARAM_NAME => AdSet::STATUS_PAUSED,
));
echo 'AdSet ID: '. $adset->id . "\n";
/* AdCreative Creation */
// --- select an image ---
$image = new AdImage(null, 'act_1XXXXXXXXXXXX3');
$image->{AdImageFields::FILENAME} = 'C:\Users\*****\Desktop\Projects\platypus.jpg';
$image->create();
echo 'Image Hash: '.$image->{AdImageFields::HASH}.PHP_EOL;
// ----------------------
$creative = new AdCreative(null, 'act_1XXXXXXXXXXXXXXXX3');
$creative->setData(array(
AdCreativeFields::NAME => 'Sample Creative',
AdCreativeFields::TITLE => 'Welcome to the Jungle',
AdCreativeFields::BODY => 'check this out',
AdCreativeFields::IMAGE_HASH => $image->hash,
AdCreativeFields::OBJECT_URL => 'http://www.google.com/',
));
$creative->create();
echo 'Creative ID: '.$creative->id . "\n";
return($creative);
/* Ad Creation */
$fields = array(
AdFields::NAME => 'My first Ad',
AdFields::ADSET_ID => '2XXXXXXXXXXXXXXXXX7',
AdFields::CREATIVE => array(
'creative_id' => '2XXXXXXXXXXXXXXXXX7',
),
AdFields::STATUS => Ad::STATUS_PAUSED,
);
$ad = new Ad(null, 'act_1XXXXXXXXXXXXXXXX3');
$ad->create($fields);
If someone have an idea...
Cordially.
Wrong repository, please post your question in the Marketing API PHP SDK repository! :)