0

自从 Savon gem 将 Ruby 代码转换为 XML 以来,我已经能够在不了解 XML 的情况下做到这一点,但现在我被困住了。我从 API 请求 CampaignPerformanceReport 并且能够成功检索我需要的数据,但现在我需要添加一个过滤器以仅获取“暂停”广告系列。

按照此文档,我将此消息发送到 API:

<env:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tns="https://bingads.microsoft.com/Reporting/v13" xmlns:env="http://schemas.xmlsoap.org/soap/envelope/" xmlns="https://bingads.microsoft.com/Reporting/v13">
  <env:Header>
    <AuthenticationToken>foo</AuthenticationToken>
    <CustomerAccountId>foo</CustomerAccountId>
    <CustomerId>foo</CustomerId>
    <DeveloperToken>foo</DeveloperToken>
  </env:Header>
  <env:Body>
    <tns:SubmitGenerateReportRequest>
      <ReportRequest xsi:nil="false" xsi:type="CampaignPerformanceReportRequest">
        <ExcludeColumnHeaders>true</ExcludeColumnHeaders>
        <ExcludeReportFooter>true</ExcludeReportFooter>
        <ExcludeReportHeader>true</ExcludeReportHeader>
        <Format>Csv</Format>
        <Language>English</Language>
        <ReportName>CampaignPerformanceReportRequest</ReportName>
        <ReturnOnlyCompleteData>false</ReturnOnlyCompleteData>
        <Aggregation>Summary</Aggregation>
        <Columns>
          <CampaignPerformanceReportColumn>CampaignName</CampaignPerformanceReportColumn>
          <CampaignPerformanceReportColumn>CampaignStatus</CampaignPerformanceReportColumn>
          <CampaignPerformanceReportColumn>Spend</CampaignPerformanceReportColumn>
          <CampaignPerformanceReportColumn>Impressions</CampaignPerformanceReportColumn>
          <CampaignPerformanceReportColumn>Clicks</CampaignPerformanceReportColumn>
          <CampaignPerformanceReportColumn>Conversions</CampaignPerformanceReportColumn>
          <CampaignPerformanceReportColumn>Revenue</CampaignPerformanceReportColumn>
          <CampaignPerformanceReportColumn>PhoneCalls</CampaignPerformanceReportColumn>
        </Columns>
        <Filter>
          <CampaignStatusReportFilter>Paused</CampaignStatusReportFilter>
        </Filter>
        <Scope>
          <AccountIds xmlns:a1="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
            <a1:long>foo</a1:long>
          </AccountIds>
        </Scope>
        <Time>
          <CustomDateRangeEnd>
            <Day>31</Day>
            <Month>01</Month>
            <Year>2019</Year>
          </CustomDateRangeEnd>
          <CustomDateRangeStart>
            <Day>01</Day>
            <Month>01</Month>
            <Year>2019</Year>
          </CustomDateRangeStart>
          <PredefinedTime xsi:nil="true"/>
          <ReportTimeZone>EasternTimeUSCanada</ReportTimeZone>
        </Time>
      </ReportRequest>
    </tns:SubmitGenerateReportRequest>
  </env:Body>
</env:Envelope>

请求被接受并处理,但返回的数据仅显示“活动”活动。我确定我的过滤方式存在问题。这是我用来生成请求的 Ruby 代码。

report_request = {
      '@xsi:nil' => false,
      '@xsi:type' => 'CampaignPerformanceReportRequest',
      'ExcludeColumnHeaders' => true,
      'ExcludeReportFooter' => true,
      'ExcludeReportHeader' => true,
      'Format' => 'Csv',
      'Language' => 'English',
      'ReportName' => 'CampaignPerformanceReportRequest',
      'ReturnOnlyCompleteData' => false,
      'Aggregation' => 'Summary',
      'Columns' => {
         'CampaignPerformanceReportColumn' => [
           'CampaignName',
           'CampaignStatus',
           'Spend',
           'Impressions',
           'Clicks',
           'Conversions',
           'Revenue',
           'PhoneCalls'
         ]
      },
      'Filter' => { 'CampaignStatusReportFilter' => 'Paused' },
      'Scope' => {
        'AccountIds' => {
          '@xmlns:a1' => 'http://schemas.microsoft.com/2003/10/Serialization/Arrays',
          'a1:long' => account_id,
        }
      },
   etc...
}

我已经尝试完全匹配上面链接到的文档中的语法,但它仍然只返回“活动”活动,这让我相信这是默认设置,API 只是忽略了我不正确的过滤。

如果有人可以帮助我弄清楚我在这里做错了什么,将不胜感激。

4

1 回答 1

1

请注意,有多种子过滤器类型可用,例如 AccountStatus、AdDistribution、DeviceOS、DeviceType 和Status

您可以使用以下语法(我今天测试并确认)仅包含设备类型为平板电脑且活动状态为已暂停的报告数据。您可以删除设备平板电脑过滤器,因为我添加它只是为了展示如何添加多个过滤器。

<Filter>
    <AccountStatus i:nil="true"/>
    <AdDistribution i:nil="true"/>
    <DeviceOS i:nil="true"/>
    <DeviceType>Tablet</DeviceType>
    <Status>Paused</Status>
</Filter>

抱歉,我手头没有 Ruby 示例,但这里有一个 C# 片段,可帮助在 SOAP 请求中生成上述 XML:

Filter = new CampaignPerformanceReportFilter {
    DeviceType = DeviceTypeReportFilter.Tablet,
    Status = CampaignStatusReportFilter.Active
},

提示:每个 Bing Ads API 服务操作都包含一个语法模板,例如SubmitGenerateReport。您只需要划分出适用于您的请求的部分,例如,一次只需要一种报告请求类型。

也请随时通过Bing Ads API 开发论坛联系我们的团队并联系支持链接。

我希望这有帮助!

于 2019-05-13T18:39:44.847 回答