1
我試圖顯示當天所有我的Facebook廣告活動的列表...Facebook廣告API - >顯示廣告活動
此代碼大多是工作,但它只能說明我的廣告系列的24 ...當我有超過100
我不知道爲什麼會......也不知過了顯示當天統計...感謝您的幫助
<?php
$app_id='ID';
$app_secret='SECRET';
$access_token = 'TOKEN';
define('SDK_DIR', __DIR__ . '/..'); // Path to the SDK directory
$loader = include SDK_DIR.'/vendor/autoload.php';
use FacebookAds\Api;
// Initialize a new Session and instanciate an Api object
Api::init($app_id, $app_secret, $access_token);
// The Api object is now available trough singleton
$api = Api::instance();
use FacebookAds\Object\AdUser;
use FacebookAds\Object\AdAccount;
use FacebookAds\Object\Fields\AdAccountFields;
use FacebookAds\Object\AdCampaign;
use FacebookAds\Object\Fields\AdCampaignFields;
use FacebookAds\Object\Fields\AdSetFields;
$me = new AdUser('me');
$accounts = $me->getAdAccounts();
// Output account ID
foreach ($accounts as $account) {
echo $account_id = $account->id;
echo "----";
}
$account = new AdAccount($account_id);
$fields = array(
AdCampaignFields::NAME,
AdCampaignFields::OBJECTIVE,
AdCampaignFields::STATUS,
);
$campaigns = $account->getAdCampaigns($fields);
?>
<table border="1" bordercolor="#6699CC" style="width:100%">
<tr>
<th bgcolor="#336699" style="color:#FFF">Campaign_id</th>
<th bgcolor="#336699" style="color:#FFF">Campaign Name</th>
<th bgcolor="#336699" style="color:#FFF">Status</th>
<th bgcolor="#336699" style="color:#FFF">Impressions</th>
<th bgcolor="#336699" style="color:#FFF">Clicks</th>
<th bgcolor="#336699" style="color:#FFF">Spent</th>
</tr>
<?PHP
foreach ($campaigns as $campaign) {
//---------------------------------
?>
<tr>
<td><?php echo $campaign->id; ?></td>
<td><?php echo $campaign->name; ?></td>
<td><?php echo $campaign->campaign_group_status ?></td>
<?php
$fields = array (
'impressions',
'clicks',
'spent',
);
$params = array (
'date_preset'=>'yesterday',
'data_columns'=>"['adgroup_id','actions','spend']",
);
$campaign = new AdCampaign($campaign->id);
$stats = $campaign->getStats($fields, $params);
foreach ($stats as $stat) {
echo '<td>'.$stat->impressions. '</td>';
echo '<td>'.$stat->clicks. '</td>';
echo '<td>'.$stat->spent. '</td>';
}
//---------------------------------
}
?>