浏览器中的php出现空白但在cli中显示输出

时间:2014-06-19 22:59:19

标签: php api google-adwords

我有以下来自google adwords api的代码,由于某种原因,有一个特定的部分阻止浏览器显示输出。我无法弄清楚原因,但有人可以告诉我如何修复以及为什么这条线会阻止浏览器显示输出但允许cli显示输出。

<?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'.\n",
      $reportDefinition->reportName, $filePath);
}

这是因某种原因导致问题的行

// Don't run the example if the file is being included.
if (__FILE__ != realpath($_SERVER['PHP_SELF'])) {

  return;
}

导致问题的行尾

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\n", $e->getMessage());
}

0 个答案:

没有答案