I have the following code from google adwords api and for some reason there is a specific section that prevents the browser from displaying output. I can't figure out why but can someone please tell me how to fix and why this line would prevent the browser from displaying output but allows the cli to display output.
<?php
// Include the initialization file
require_once 'src/Google/Api/Ads/AdWords/init.php';
require_once ADWORDS_UTIL_PATH . '/ReportUtils.php';
/**
* Runs the example.
* @param AdWordsUser $user the user to run the example with
* @param string $filePath the path of the file to download the report to
*/
function DownloadCriteriaReportExample(AdWordsUser $user, $filePath) {
// Load the service, so that the required classes are available.
$user->LoadService('ReportDefinitionService', ADWORDS_VERSION);
// Create selector.
$selector = new Selector();
$selector->fields = array('CampaignName', 'AdGroupName', 'Criteria',
'AverageCpc', 'Impressions', 'Clicks', 'Cost', 'AveragePosition', 'Ctr');
// Filter out deleted criteria.
$selector->predicates[] = new Predicate('Status', 'NOT_IN', array('DELETED'));
// Create report definition.
$reportDefinition = new ReportDefinition();
$reportDefinition->selector = $selector;
$reportDefinition->reportName = 'Criteria performance report #' . uniqid();
$reportDefinition->dateRangeType = 'LAST_30_DAYS';
$reportDefinition->reportType = 'CRITERIA_PERFORMANCE_REPORT';
$reportDefinition->downloadFormat = 'CSV';
// Exclude criteria that haven't recieved any impressions over the date range.
$reportDefinition->includeZeroImpressions = FALSE;
// Set additional options.
$options = array('version' => ADWORDS_VERSION, 'returnMoneyInMicros' => FALSE);
// Download report.
ReportUtils::DownloadReport($reportDefinition, $filePath, $user, $options);
printf("Report with name '%s' was downloaded to '%s'.
",
$reportDefinition->reportName, $filePath);
}
This is the line that is causing the issue for some reason
// Don't run the example if the file is being included.
if (__FILE__ != realpath($_SERVER['PHP_SELF'])) {
return;
}
End of line causing issue
try {
// Get AdWordsUser from credentials in "../auth.ini"
// relative to the AdWordsUser.php file's directory.
$user = new AdWordsUser();
// Log every SOAP XML request and response.
$user->LogAll();
// Download the report to a file in the same directory as the example.
$filePath = dirname(__FILE__) . '/report.csv';
// Run the example.
DownloadCriteriaReportExample($user, $filePath);
} catch (Exception $e) {
printf("An error has occurred: %s
", $e->getMessage());
}