private function downloadCSVReportActivity($access_token, $expires_in,$timestamp, $clientCustomerId, $fromDate, $toDate) {
$user = new \AdWordsUser();
$user->LogAll();
$user->SetClientCustomerId($clientCustomerId);
$oAuth2Info = $user->GetOAuth2Info();
//SET access token value in oauth..
//thsi is required while using new service
$oAuth2Info['access_token'] = $access_token;
$oAuth2Info['expires_in'] = $expires_in;
$oAuth2Info['timestamp'] = $timestamp;
// Download report.
$user->SetOAuth2Info($oAuth2Info);
$campaignService = $user->GetService('CampaignService', "v201605");
$customerSyncService = $user->GetService('CustomerSyncService', "v201605");
// Get an array of all campaign ids.
$campaignIds = array();
$selector = new \Selector();
$selector->fields = array('Id', 'Name', 'Status');
$selector->paging = new \Paging(0, 500);
$selector->predicates[] = new \Predicate('Status', 'IN', array('ENABLED'));
do {
$page = $campaignService->get($selector);
if (isset($page->entries)) {
foreach ($page->entries as $campaign) {
//get all campaign id corresponding to its name
$campaignIds[$campaign->id] = $campaign->name;
}
}
$selector->paging->startIndex += 500;
} while ($page->totalNumEntries > $selector->paging->startIndex);
$activityGraphArr = array();
// Set the date time range, from 24 hours ago until now.
$dateTimeRange = new \DateTimeRange();
//initialize the count to 0
if(!empty($campaignIds)){
//bug fixed: display account activity for 90 days instead of 12 weeks
try{
for ($i = 0; $i < 12; $i++) {
$count = 0;
//fetch data weekly.. so set date by subtracting the days from min nd max date
$subDays = 7 * $i;
$fdate = date('Y-m-d', strtotime('-' . $subDays . 'day', strtotime($fromDate)));
$tdate = date('Y-m-d', strtotime('-' . $subDays . 'day', strtotime($toDate)));
$dateTimeRange->min = date('Ymd his', strtotime($fdate));
$dateTimeRange->max = date('Ymd his', strtotime($tdate));
// Create selector.
//get customer acc setting from $customerSyncService
$selector = new \CustomerSyncSelector();
$selector->dateTimeRange = $dateTimeRange;
$selector->campaignIds = array_keys($campaignIds);
// Make the get request.
$accountChanges = $customerSyncService->get($selector);
if (isset($accountChanges)) {
foreach ($accountChanges->changedCampaigns as $campaignChangeData) {
if ($campaignChangeData->campaignChangeStatus != 'NEW') {
//add all the changes to get the total number of times changes
//are made
$count +=!empty($campaignChangeData->removedAdExtensions) ?
sizeOf($campaignChangeData->removedAdExtensions) : 0;
$count +=!empty($campaignChangeData->addedCampaignCriteria) ?
sizeOf($campaignChangeData->addedCampaignCriteria) : 0;
$count +=!empty($campaignChangeData->removedCampaignCriteria) ?
sizeOf($campaignChangeData->removedCampaignCriteria) : 0;
if (isset($campaignChangeData->changedAdGroups)) {
foreach ($campaignChangeData->changedAdGroups as $adGroupChangeData) {
if ($adGroupChangeData->adGroupChangeStatus != 'NEW') {
$count +=!empty($adGroupChangeData->changedAds) ?
sizeOf($adGroupChangeData->changedAds) : 0;
}
}
}
}
}
//push date and count into array
$graphArr[0] = $fdate;
$graphArr[1] = $count;
array_push($activityGraphArr, $graphArr);
}
}
}catch (Exception $ex) {
$this->log($ex->getMessage(), "error");
}
}
return $activityGraphArr;
}