Bing 广告 Java API BudgetSummaryReportRequest 示例代码

Bing Ads Java API BudgetSummaryReportRequest example code

我正在尝试从 Bing 广告文档中 运行 基本 report download example 并且我设法修改示例代码以通过更改 get<REPORT_TYPE>ReportRequest() 方法。

我遇到的一种报告类型是预算汇总报告。

我这样创建报告请求:

private static ReportRequest getBudgetSummaryReportRequest(){
        BudgetSummaryReportRequest report = new BudgetSummaryReportRequest();

        report.setFormat(ReportFormat.CSV);
        report.setReportName("My Budget Summary Report");
        report.setReturnOnlyCompleteData(false);

        ArrayOflong accountIds = new ArrayOflong();
        accountIds.getLongs().add(authorizationData.getAccountId());


        report.setScope(new AccountThroughCampaignReportScope());
        report.getScope().setAccountIds(accountIds);
        ArrayOfCampaignReportScope c = new ArrayOfCampaignReportScope();
        CampaignReportScope cc = new CampaignReportScope();
        cc.setAccountId(authorizationData.getAccountId());
        cc.setCampaignId(<MY_CAMPAIGN_ID>);
        c.getCampaignReportScopes().add(cc);
        report.getScope().setCampaigns(c);

        report.setTime(new BudgetSummaryReportTime());
         report.getTime().setPredefinedTime(BudgetSummaryReportTimePeriod.TODAY);

        ArrayOfBudgetSummaryReportColumn budgetSummaryReportColumns = new ArrayOfBudgetSummaryReportColumn();
        budgetSummaryReportColumns.getBudgetSummaryReportColumns().add(BudgetSummaryReportColumn.ACCOUNT_ID);
        budgetSummaryReportColumns.getBudgetSummaryReportColumns().add(BudgetSummaryReportColumn.CAMPAIGN_ID);
        budgetSummaryReportColumns.getBudgetSummaryReportColumns().add(BudgetSummaryReportColumn.DATE);
        budgetSummaryReportColumns.getBudgetSummaryReportColumns().add(BudgetSummaryReportColumn.CURRENCY_CODE);
        budgetSummaryReportColumns.getBudgetSummaryReportColumns().add(BudgetSummaryReportColumn.MONTHLY_BUDGET);
        budgetSummaryReportColumns.getBudgetSummaryReportColumns().add(BudgetSummaryReportColumn.MONTH_TO_DATE_SPEND);
        budgetSummaryReportColumns.getBudgetSummaryReportColumns().add(BudgetSummaryReportColumn.DAILY_SPEND);

        return report;
    }

然后在 main 方法中使用 ReportRequest 对象(参见示例中的 reportRequest 字段)。但无论我做什么,当我尝试 运行 时,我总是会收到以下错误:

java.util.concurrent.ExecutionException: com.microsoft.bingads.reporting.CouldNotSubmitReportingDownloadException: java.util.concurrent.ExecutionException: com.microsoft.bingads.reporting.ApiFaultDetail_Exception: Invalid client data. Check the SOAP fault details for more information
    at com.microsoft.bingads.internal.ResultFuture.get(ResultFuture.java:96)
    at ads.ReportRequests.backgroundCompletion(ReportRequests.java:172)
    at ads.ReportRequests.main(ReportRequests.java:90)
Caused by: com.microsoft.bingads.reporting.CouldNotSubmitReportingDownloadException: java.util.concurrent.ExecutionException: com.microsoft.bingads.reporting.ApiFaultDetail_Exception: Invalid client data. Check the SOAP fault details for more information
    at com.microsoft.bingads.reporting.ReportingServiceManager.handleResponse(ReportingServiceManager.java:216)
    at org.apache.cxf.jaxws.JaxwsClientCallback.handleException(JaxwsClientCallback.java:87)
    at org.apache.cxf.endpoint.ClientImpl.onMessage(ClientImpl.java:821)
    at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.handleResponseInternal(HTTPConduit.java:1638)
    at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.run(HTTPConduit.java:1145)
    at org.apache.cxf.workqueue.AutomaticWorkQueueImpl.run(AutomaticWorkQueueImpl.java:428)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at org.apache.cxf.workqueue.AutomaticWorkQueueImpl$AWQThreadFactory.run(AutomaticWorkQueueImpl.java:353)
    at java.lang.Thread.run(Unknown Source)
Caused by: java.util.concurrent.ExecutionException: com.microsoft.bingads.reporting.ApiFaultDetail_Exception: Invalid client data. Check the SOAP fault details for more information
    at org.apache.cxf.jaxws.JaxwsClientCallback.get(JaxwsClientCallback.java:99)
    at com.microsoft.bingads.reporting.ReportingServiceManager.handleResponse(ReportingServiceManager.java:202)
    ... 9 more
Caused by: com.microsoft.bingads.reporting.ApiFaultDetail_Exception: Invalid client data. Check the SOAP fault details for more information
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
    at java.lang.reflect.Constructor.newInstance(Unknown Source)
    at org.apache.cxf.interceptor.ClientFaultConverter.processFaultDetail(ClientFaultConverter.java:182)
    at org.apache.cxf.interceptor.ClientFaultConverter.handleMessage(ClientFaultConverter.java:82)
    at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:307)
    at org.apache.cxf.interceptor.AbstractFaultChainInitiatorObserver.onMessage(AbstractFaultChainInitiatorObserver.java:113)
    at org.apache.cxf.jaxws.handler.soap.SOAPHandlerInterceptor.handleMessage(SOAPHandlerInterceptor.java:140)
    at org.apache.cxf.jaxws.handler.soap.SOAPHandlerInterceptor.handleMessage(SOAPHandlerInterceptor.java:71)
    at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:307)
    at org.apache.cxf.endpoint.ClientImpl.onMessage(ClientImpl.java:780)
    ... 7 more

对于其他报告类型,此错误通常意味着我忘记设置一些必需的参数(例如范围)。在这里我只是不知道。我该如何调试这个问题(例如检查 "SOAP data" 错误消息中提到的)?

有人有预算摘要报告下载的工作示例吗?

编辑: 下面 Eric Urban 的回答解决了我的问题。每个报告请求类型都有一些需要手动指定并添加到 ReportRequest 对象的列。

几个更新应该可以解决这个问题。首先,您需要添加缺少的必需列。核心服务参考指南中的每个值集都记录了所需的列,例如请参阅 BudgetSummaryReportColumn Value Set。其次,您需要将列数组添加到报告请求中。

budgetSummaryReportColumns.getBudgetSummaryReportColumns().add(BudgetSummaryReportColumn.ACCOUNT_NAME);
budgetSummaryReportColumns.getBudgetSummaryReportColumns().add(BudgetSummaryReportColumn.ACCOUNT_NUMBER);
budgetSummaryReportColumns.getBudgetSummaryReportColumns().add(BudgetSummaryReportColumn.CAMPAIGN_NAME);
report.setColumns(budgetSummaryReportColumns);

有关如何捕获 SOAP 请求和响应的详细信息,请参阅 Troubleshooting Bing Ads Java SDK。例如,我目前正在使用 Spring Framework 和 Apache CXF。

希望对您有所帮助!