Uwe*_*eim 2 .net api google-api google-adwords
大约一年后成功使用此SO解决方案,我的代码来获取Google AdWords广告系列的每日费用如下所示:
sum += campaign.campaignStats.cost.microAmount / 1000000m;
Run Code Online (Sandbox Code Playgroud)
即我正在使用该campaignStats物业.
不幸的是,在API 的最新版本v201309中,此属性不再存在.
我搜索了官方.NET包装器的所有示例,并查看了API文档,但没有找到关于如何管理它的单一线索.
因此我的问题是:
如何通过最新的Google AdWords API检索AdWord campain的每日费用?
更新1:
我在AdWords API论坛中发现了这个讨论.他们建议生成报告,获取并解析此报告.还有关于它的AdWords博客文章.
小智 5
这是一个PHP版本:
$ filePath = tempnam('/ tmp','adwordsreport');
$user = new AdWordsUser(NULL, NULL, NULL, $developerToken, $applicationToken, $userAgent, $ClientID, NULL, NULL, $oauth2Info);
$user->SetClientId($ClientID);
// Log SOAP XML request and response.
$user->LogDefaults();
$user->LoadService('ReportDefinitionService', 'v201402');
// Create selector.
$selector = new Selector();
$selector->fields = array('CampaignId', 'AdGroupId', 'Id', 'Criteria',
'CriteriaType', 'Impressions', 'Clicks', 'Cost');
// Filter out deleted criteria.
$selector->predicates[] = new Predicate('Status', 'NOT_IN', array('DELETED'));
// Create report definition.
$reportDefinition = new ReportDefinition();
$reportDefinition->selector = $selector;
$reportDefinition->reportName = 'Criteria performance report #' . uniqid();
$reportDefinition->dateRangeType = 'ALL_TIME';
$reportDefinition->reportType = 'CRITERIA_PERFORMANCE_REPORT';
$reportDefinition->downloadFormat = 'XML';
// Exclude criteria that haven't recieved any impressions over the date range.
$reportDefinition->includeZeroImpressions = FALSE;
// Set additional options.
$options = array('version' => 'v201402', 'returnMoneyInMicros' => TRUE);
// Download report.
ReportUtils::DownloadReport($reportDefinition, $filePath, $user, $options);
printf("Report with name '%s' was downloaded to '%s'.\n",
$reportDefinition->reportName, $filePath);
$doc = new DOMDocument();
$doc->loadXML(file_get_contents($filePath));
$xp = new DOMXPath($doc);
$q = $xp->query("/report/table/row/@cost");
$cost = 0;
foreach($q as $el) {
$v = $el->textContent;
$cost += $v / 1000000;
}
echo $cost;
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5055 次 |
| 最近记录: |