我抓住與用戶關聯的所有廣告系列並試圖獲取廣告系列的見解。我獲得了廣告系列,但是當我嘗試獲取洞察時,它總是返回null。我試圖改變日子和不同的領域。活動洞察力返回null Facebook營銷API
$api = Api::instance();
$id = trim($_POST['actid']);
$account = new AdAccount($id);
$fields = array(
CampaignFields::NAME,
CampaignFields::ID,
);
$campaigns = $account->getCampaigns($fields);
$cleanArray = [];
foreach ($campaigns as $campaign) {
$campFields = array(
AdsInsightsFields::CPC,
);
$params = array(
'time_range' => array(
'since' => (new DateTime("-1 day"))->format('Y-m-d'),
'until' => (new DateTime('NOW'))->format('Y-m-d'),
),
);
$campInsights = $campSelect->getInsights($campFields, $params);
$innerArray = [];
array_push($innerArray,$campaign->{CampaignFields::NAME});
array_push($innerArray,$campaign->{CampaignFields::ID});
array_push($innerArray,$campInsights->{AdsInsightsFields::CPC});
array_push($cleanArray,$innerArray);
}
header('Content-Type: application/json');
echo json_encode($cleanArray);
感謝您的支持。這實際上是一個範圍問題。我張貼我的答案,以幫助其他人作爲他們的文檔不是很好。 –