adwords api: retrieve daily spend (costs)

泄露秘密 提交于 2019-12-10 15:05:57

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!