AdWords API PHP问题

AdWords API PHP问题,php,soap,google-ads-api,Php,Soap,Google Ads Api,在php中使用Adwords API时,我在找出代码的错误方面遇到了一些实际问题。我试图检索简单的活动统计数据,以便输入本地数据库。然而,我无法做到这一点。我正在使用最初下载的示例,但是返回一个完全空白的屏幕,没有任何有用的错误消息。下面是我的代码,我希望这里有人遇到了这个问题,可以帮助我解决这个问题 require_once 'Api/Ads/AdWords/Lib/AdWordsUser.php'; require_once 'Api/Ads/AdWords/Util/ReportU

在php中使用Adwords API时,我在找出代码的错误方面遇到了一些实际问题。我试图检索简单的活动统计数据,以便输入本地数据库。然而,我无法做到这一点。我正在使用最初下载的示例,但是返回一个完全空白的屏幕,没有任何有用的错误消息。下面是我的代码,我希望这里有人遇到了这个问题,可以帮助我解决这个问题

    require_once 'Api/Ads/AdWords/Lib/AdWordsUser.php';
require_once 'Api/Ads/AdWords/Util/ReportUtils.php';

function GetCampaignStatsExample(AdWordsUser $user) {
    // Get the service, which loads the required classes.
    $campaignService = $user->GetService('CampaignService', ADWORDS_VERSION);

    // Create selector.
    $selector = new Selector();
    $selector->fields = array('Id', 'Name', 'Impressions', 'Clicks', 'Cost', 'Ctr');
    $selector->predicates[] = new Predicate('Impressions', 'GREATER_THAN', array(0));

    // Set date range to request stats for.
    $dateRange = new DateRange();
    $dateRange->min = date('Ymd', strtotime('-1 week'));
    $dateRange->max = date('Ymd', strtotime('-1 day'));
    $selector->dateRange = $dateRange;

    // Create paging controls.
    $selector->paging = new Paging(0, AdWordsConstants::RECOMMENDED_PAGE_SIZE);

    do {
        // Make the get request.
        $page = $campaignService->get($selector);

        // Display results.
        if (isset($page->entries)) {
            foreach ($page->entries as $campaign) {
                print_r("Campaign with name '%s' and id '%s' had the following stats " . "during the last week:\n", $campaign->name, $campaign->id);
                print_r("  Impressions: %d\n", $campaign->campaignStats->impressions);
                print_r("  Clicks: %d\n", $campaign->campaignStats->clicks);
                print_r("  Cost: $%.2f\n", $campaign->campaignStats->cost->microAmount / AdWordsConstants::MICROS_PER_DOLLAR);
                print_r("  CTR: %.2f%%\n", $campaign->campaignStats->ctr * 100);
            }
        } 
        else {
            print "No matching campaigns were found.\n";
        }

        // Advance the paging index.
        $selector->paging->startIndex += AdWordsConstants::RECOMMENDED_PAGE_SIZE;
    } 
    while ($page->totalNumEntries > $selector->paging->startIndex);
}

// 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();

    // Run the example.
    GetCampaignStatsExample($user);
} 
catch (OAuth2Exception $e) {
    ExampleUtils::CheckForOAuth2Errors($e);
} 
catch (ValidationException $e) {
    ExampleUtils::CheckForOAuth2Errors($e);
} 
catch (Exception $e) {
    print_r("An error has occurred: %s\n", $e->getMessage());
}

您需要从CLI运行此命令。 单击开始并运行,您将看到一个黑屏 在命令行界面中键入此命令

C:\wamp\bin\php\php5.4.3\php.exe -f "C:\wamp\www\AAAMYBUILD\timenow.php"
如果第一个位置是您的php.exe文件,并且第二个位置是您要运行的实际文件,则将运行该文件

您将在此窗口中看到结果,而不是浏览器


看起来您应该能够在浏览器中运行这些文件,但我也从来没有这样做过

这是因为本例希望您通过命令行运行它。如果要在浏览器中运行,可以删除代码的以下部分:

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