Google Adwords API - 每日花在PHP上

时间:2015-02-18 12:21:31

标签: google-api google-adwords google-api-php-client

我刚刚在我的服务器上安装了Google API。 目的是获得帐户的每日费用。 我正在玩“GetCampaigns.php”#39;例如,使用' CampaignService'服务。此服务具有不同的字段,例如Id,Name,Amount和许多其他字段。我希望下面的代码能够抓住所有广告系列并打印他们的名字和金额。

<?php
require_once dirname(dirname(__FILE__)) . '/init.php';
function GetCampaignsExample(AdWordsUser $user) {
  $campaignService = $user->GetService('CampaignService', ADWORDS_VERSION);  
  $selector = new Selector();
  $selector->fields = array('Name', 'Amount');
  $selector->ordering[] = new OrderBy('Name', 'ASCENDING');

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

  do {
    $page = $campaignService->get($selector);

    if (isset($page->entries)) {
      foreach ($page->entries as $campaign) {
        printf("Campaign with name '%s' with amount '%s' was found.\n",
            $campaign->name, $campaign->amount);
      }
    } else {
      print "No campaigns were found.\n";
    }

    $selector->paging->startIndex += AdWordsConstants::RECOMMENDED_PAGE_SIZE;
  } while ($page->totalNumEntries > $selector->paging->startIndex);
}

if (__FILE__ != realpath($_SERVER['PHP_SELF'])) {
//  return;
}

try {
  $user = new AdWordsUser();
  $user->LogAll();
  GetCampaignsExample($user);
} catch (Exception $e) {
  printf("An error has occurred: %s\n", $e->getMessage());
}
?>

但是,我不明白页面输出的原因:

  

注意:未定义的属性:Campaign :: $ amount in   /public_html/adwords/examples/AdWords/v201409/BasicOperations/GetCampaigns.php   第17行广告系列名称&#39;我的广告系列&#39;和金额&#39;&#39;被发现了。

已成功检索名称,但金额不是。

可能有人有一个完整的解决方案来获得日期范围的总预算吗?

谢谢

0 个答案:

没有答案