AdWords API:获取每日支出(成本)
有没有人能提供一些示例代码,展示如何获取一个AdWords账户每天的总花费(所有广告活动的花费加起来)?
我一直找不到简单明了的示例代码来做到这一点,所以任何帮助、建议或者代码都非常感谢。(我会使用Python库,但其他语言的代码也没问题……)
提前谢谢大家!
Hoff
1 个回答
0
我对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
的示例,点击这里,来写出相应的Python代码。