adwords api:检索每日支出(费用)

时间:2011-06-15 15:10:36

标签: python api google-api google-adwords

是否有人提供一些示例代码,说明如何获取AdWords帐户的每日总支出(所有广告系列)?

我无法找到以简单方式执行此类操作的示例代码,因此任何帮助,指针,代码都将受到赞赏。 (我将使用python lib,但任何其他语言也很酷......)

提前致谢!

霍夫

1 个答案:

答案 0 :(得分:1)

我不熟悉Python,但这个过程应该在任何语言中都类似,所以这个PHP可能会有所帮助:

$user = new AdWordsUser();

// Get the CampaignService.
$campaignService = $user->GetCampaignService('v201101');

// Create selector.
$selector = new Selector();
// Fields to retrieve
$selector->fields = array('Id', 'Name', 'Cost');
// Date rage for stats
$selector->dateRange->min = "20110613";
$selector->dateRange->max = "20110614";

// Get all campaigns.
$page = $campaignService->get($selector);

if(isset($page->entries)){
    foreach ($page->entries as $campaign) {
        if(isset($campaign->campaignStats)) {
            // This is how you get the cost
            $cost = $campaign->campaignStats->cost->microAmount/1000000;
            print "Cost for Campaign {$campaign->name} = $cost\n";
        }
    }
}

您应该能够使用get_all_campaigns.py示例here编写等效的Python代码。