Amit
Amit

Reputation: 65

Facebook Marketing API Campaign Start & End Date

I am able to get the campaign insights such as campaign name, reach, video views using the Facebook marketing API, but I am not able to get Campaign Start and Campaign END date.

     $fields = array(
  CampaignFields::NAME,
  CampaignFields::OBJECTIVE,
  CampaignFields::STATUS,

);

$campaigns = $account->getCampaigns($fields);
?>

  <?php

foreach ($campaigns as $campaign) {
//---------------------------------
?>

<tr>
<td><?php echo $campaign->id; ?></td>
<td><?php echo $campaign->name; ?></td>

<?php
$fields = array (
    'reach',    
    'impressions',
    'website_clicks',
    'cpm',
    'video_10_sec_watched_actions',
    'video_avg_sec_watched_actions',
);  

$params = array (
    'date_preset'=>'last_30_days',
    'data_columns'=>"['adgroup_id','actions','reach']",
);

?>


<?php

$campaign = new Campaign($campaign->id);
$insights = $campaign->getinsights($fields, $params);

foreach ($insights as $insight) {
        echo '<td>'.$insight->reach. '</td>';
        echo '<td>'.$insight->impressions. '</td>';
        echo '<td>'.$insight->website_clicks. '</td>';
        echo '<td>'.$insight->cpm. '</td>';
//        echo '<td>'.$insight->video_10_sec_watched_actions. '</td>';
//        echo '<td>'.$insight->video_avg_sec_watched_actions. '</td>';
//      
}
        // find video views
        $videoview = 0;
//        $postEngagement = -1;
    printf('<td>%s</td>', $insight->video_10_sec_watched_actions[0]['value']);

Upvotes: 1

Views: 2594

Answers (1)

Nadeem0035
Nadeem0035

Reputation: 3957

To get Campaign Start and Campaign END date use "START_TIME" and "STOP_TIME" Fields.

$fields = array(
    CampaignFields::NAME,
    CampaignFields::OBJECTIVE,
    CampaignFields::STATUS,
    CampaignFields::CREATED_TIME,
    CampaignFields::START_TIME,
    CampaignFields::STOP_TIME,
    CampaignFields::UPDATED_TIME,
);

Campaign Fields

Upvotes: 2

Related Questions