We are using Laravel 5.7, PHP 7.1 and XAMPP 3.2.2 We want to create Facebook Campaigns using the PHP Business SDK and Marketing API.
The campaign is created successfully through the following source code
/* Start Campaign*/
$fields = array(
);
$params = array(
'name' => $request->campaign_name,
'objective' => 'LINK_CLICKS',
'status' => 'PAUSED',
);
$campaignData = ((new AdAccount($account_id))->createCampaign(
$fields,
$params
)->exportAllData());
/* End Campaign*/
this, I try to write the source code for the AdSet but I get the following error "$parent_id as a parameter of constructor is being deprecated, please try not to use this in new code." At the following line
$adset = new AdSet(null, $account_id);
Below you will find all of my source code for the creation of the AdSet
$start_time = (new DateTime("+1 week"))->format(DateTime::ISO8601);
$end_time = (new DateTime("+2 week"))->format(DateTime::ISO8601);
$adset = new AdSet(null,$account_id);
$adset->setData(array(
AdSetFields::NAME => 'My Ad Set',
AdSetFields::OPTIMIZATION_GOAL => AdSetOptimizationGoalValues::REACH,
AdSetFields::BILLING_EVENT => AdSetBillingEventValues::IMPRESSIONS,
AdSetFields::BID_AMOUNT => 2,
AdSetFields::DAILY_BUDGET => 1000,
AdSetFields::CAMPAIGN_ID => $campaignData['id'],
AdSetFields::TARGETING => $targeting,
AdSetFields::START_TIME => $start_time,
AdSetFields::END_TIME => $end_time,
));
$adset->create(array(
AdSet::STATUS_PARAM_NAME => AdSet::STATUS_PAUSED,
));
Trying to solve the issue I faced, I have modified the following
$adset = new AdSet(null, $account_id);
to
$adset = new AdSet($account_id);
And my new source code is the following.
$adset = new AdSet($account_id);
$adset->setData(array(
AdSetFields::NAME => 'My Ad Set',
AdSetFields::OPTIMIZATION_GOAL => AdSetOptimizationGoalValues::REACH,
AdSetFields::BILLING_EVENT => AdSetBillingEventValues::IMPRESSIONS,
AdSetFields::BID_AMOUNT => 2,
AdSetFields::DAILY_BUDGET => 1000,
AdSetFields::CAMPAIGN_ID => $campaignData['id'],
AdSetFields::TARGETING => $targeting,
AdSetFields::START_TIME => $start_time,
AdSetFields::END_TIME => $end_time,
));
$adset->create(array(
AdSet::STATUS_PARAM_NAME => AdSet::STATUS_PAUSED,
));
And now I get the error "Object has already an ID" on the following line
$adset->create(array(
Can you please help me to find out what is going and where I making the mistake?