开发者

adwords api: retrieve daily spend (costs)

开发者 https://www.devze.com 2023-03-13 09:05 出处:网络
Does anybody have some sample code that shows how to get the daily, 开发者_StackOverflow社区total spend (across all campaigns) of an AdWords account?

Does anybody have some sample code that shows how to get the daily, 开发者_StackOverflow社区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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号