1
PHPを使用して広告を作成しようとすると、広告を作成するときにadset_idフィールドが表示されません。 $ adset変数をdd()すると、idはnullになります。ここにコードとデータのダンプがあります:Facebook Marketing API Adsetを使用するとIDがnull
public function createCampaign(Request $request){
$campaign = new Campaign(null, env('FACEBOOK_ACCOUNT_ID'));
$campaign->setData([
CampaignFields::NAME => "Treat Me At Home Campaign For {$request-
>user()->name}",
CampaignFields::OBJECTIVE => CampaignObjectiveValues::LINK_CLICKS,
]);
$campaign->create([
Campaign::STATUS_PARAM_NAME => Campaign::STATUS_ACTIVE,
]);
$request->user()->campaign_id = $campaign->id;
$request->user()->save();
$targeting = new Targeting();
$targeting->{TargetingFields::GEO_LOCATIONS} =
array(
'zips' => array("{'key':'US:{$request->zip}'}")
);
$start_time = Carbon::now()->toIso8601String();
$end_time = Carbon::now()->addMonth()->toIso8601String();
$adset = new AdSet(null, env('FACEBOOK_ACCOUNT_ID'));
$adset->setData(array(
AdSetFields::NAME => "{$request->user()->name} Ad Set",
AdSetFields::BILLING_EVENT => AdSetBillingEventValues::IMPRESSIONS,
AdSetFields::OPTIMIZATION_GOAL =>
AdSetOptimizationGoalValues::REACH,
'effective_status' => AdSet::STATUS_PAUSED,
AdSetFields::BID_AMOUNT => 2,
AdSetFields::DAILY_BUDGET => round(($request->monthly_amount *
.9)/30),
AdSetFields::CAMPAIGN_ID => $request->user()->campaign_id,
AdSetFields::TARGETING => $targeting,
AdSetFields::START_TIME => $start_time,
AdSetFields::END_TIME => $end_time,
));
$image = new AdImage(null, env('FACEBOOK_ACCOUNT_ID'));
$image->{AdImageFields::FILENAME} = public_path("https://stackoverflow.com/users/{$request-
>user()->id}/profile_pic.jpg");
$image->create();
$link_data = new AdCreativeLinkData();
$link_data->setData(array(
AdCreativeLinkDataFields::MESSAGE => $request->message,
AdCreativeLinkDataFields::LINK =>
"https://treatmeathome.online/providers/{$request->user()->username}",
AdCreativeLinkDataFields::CAPTION =>
"https://treatmeathome.online/providers/{$request->user()-
>username}",
AdCreativeLinkDataFields::IMAGE_HASH => $image->
{AdImageFields::HASH},
));
$object_story_spec = new AdCreativeObjectStorySpec();
$object_story_spec->setData(array(
AdCreativeObjectStorySpecFields::PAGE_ID => '449735951890448',
AdCreativeObjectStorySpecFields::LINK_DATA => $link_data,
));
$creative = new AdCreative(null, env('FACEBOOK_ACCOUNT_ID'));
$creative->setData(array(
AdCreativeFields::NAME => "Creative for {$request->user()->name}",
AdCreativeFields::OBJECT_STORY_SPEC => $object_story_spec,
));
$creative->create();
$data = array(
AdFields::NAME => "Ad for {$request->user()->name}",
AdFields::ADSET_ID => $adset->id,
AdFields::CREATIVE => array(
'creative_id' => $creative->id,
),
);
dd($data);
$ad = new Ad(null, env('FACEBOOK_ACCOUNT_ID'));
$ad->setData($data);
$ad->create(array(
Ad::STATUS_PARAM_NAME => Ad::STATUS_PAUSED,
));
dd($ad);
return redirect('home');
}
array:3 [▼
"name" => "Ad for Jyrone Parker"
"adset_id" => null
"creative" => array:1 [▼
"creative_id" => "6076404535842"
]
]
だからこそこれはなぜですか?どんな助けでも大歓迎です!
あなたの答えを詳細に検討する必要があります。 – nyedidikeke
それはまさにそれでした。 –