问题
Does anybody have some sample code that shows how to get the daily, total spend (across all campaigns) of an AdWords account?
I haven't been able to find sample code that does something like this in a straightforward manner, so any help, pointers,code would be appreciated. (I'll use the python lib but any other language is cool, too...)
Thanks in advance!
Hoff
回答1:
I'm not familiar with Python but the process should be similar in any language so this PHP might be of some help:
$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";
}
}
}
You should be able to use the get_all_campaigns.py
example here to write the equivalent Python code.
来源:https://stackoverflow.com/questions/6359972/adwords-api-retrieve-daily-spend-costs