Google AdWords v201206 DotNet客户端GetClientReport出现问题

时间:2012-09-20 18:44:23

标签: c# .net google-adwords

这就是我正在做的事情:

Selector selector = new Selector();
selector.fields = new string[] {"CampaignId", "AdGroupId", "Id", "CriteriaType", "Criteria", "CriteriaDestinationUrl", "Clicks", "Impressions", "Cost"};
Predicate predicate = new Predicate();
predicate.field = "Status";
predicate.@operator = PredicateOperator.IN;
predicate.values = new string[] { "ACTIVE", "PAUSED" };
selector.predicates = new Predicate[] { predicate };

ReportDefinition definition = new ReportDefinition();
definition.reportName = "criteria report";
definition.reportType = ReportDefinitionReportType.CRITERIA_PERFORMANCE_REPORT;
definition.downloadFormat = DownloadFormat.XML;
definition.dateRangeType = ReportDefinitionDateRangeType.YESTERDAY;
definition.selector = selector;
definition.includeZeroImpressions = true;

_handler.RunReport(new AdWordsUser(), definition);

这是我的处理程序方法:

public void RunReport(AdWordsUser user, ReportDefinition definition)
{

    if (definition != null)
    {

        string reportContents = string.Empty;

        try
        {
            ReportUtilities utilities = new ReportUtilities(user);
            utilities.ReportVersion = "v201206";
            ClientReport report = utilities.GetClientReport(definition);
            reportContents = report.Contents.ToString();
        }
        catch (Exception ex)
        {
            _errorHandler.AddError(ex);
        }
    }
}   

我单步执行此操作时出现此错误:

Report contents are invalid. - !!!2|||-1|||[ReportDefinitionError.CUSTOMER_SERVING_TYPE_REPORT_MISMATCH @ selector]???

一直在寻找寻找解决方案的好几个小时。任何提示?

1 个答案:

答案 0 :(得分:0)

看来问题确实需要传入customerClientID。

This document帮助我了解正在发生的事情。

我最终修改了我的代码:

var configOptions = new Dictionary<string,string>();
configOptions.Add("clientCustomerID", customerID.ToString());
_handler.RunReport(new AdWordsUser(configOptions), definition);