我们正在使用 Laravel 5.7、PHP 7.1 和 XAMPP 3.2.2 我们想使用 PHP Business SDK 和 Marketing API 创建 Facebook 营销活动。
通过以下源码成功创建活动
/* 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*/
为此,我尝试编写 AdSet 的源代码,但出现以下错误“$parent_id 作为构造函数的参数已被弃用,请尽量不要在新代码中使用它。” 在以下行
$adset = new AdSet(null, $account_id);
您将在下面找到我创建 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,
));
试图解决我面临的问题,我修改了以下内容
$adset = new AdSet(null, $account_id);
至
$adset = new AdSet($account_id);
我的新源代码如下。
$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,
));
现在我在以下行收到错误“对象已经有一个 ID”
$adset->create(array(
你能帮我找出发生了什么以及我在哪里犯了错误吗?