CampaignPerformanceReportRequest return 是否适用于所有广告系列?

Can CampaignPerformanceReportRequest return for all campaigns?

尝试使用 Bing 广告 API 复制我在每小时报告中看到的内容。

不幸的是,即使我经过了正确的身份验证,我得到的数据也仅适用于一个广告系列(每天大约有 1 次展示)。我可以很好地看到 UI 中的数据,但是通过 API 验证为同一用户,我似乎只能取回较小的数据集。我正在使用 https://github.com/BingAds/BingAds-Python-SDK 并将我的代码基于示例:

def get_hourly_report(
        account_id,
        report_file_format,
        return_only_complete_data,
        time):
    report_request = reporting_service.factory.create('CampaignPerformanceReportRequest')
    report_request.Aggregation = 'Hourly'
    report_request.Format = report_file_format
    report_request.ReturnOnlyCompleteData = return_only_complete_data
    report_request.Time = time
    report_request.ReportName = "Hourly Bing Report"
    scope = reporting_service.factory.create('AccountThroughCampaignReportScope')
    scope.AccountIds = {'long': [account_id]}
    # scope.Campaigns = reporting_service.factory.create('ArrayOfCampaignReportScope');
    # scope.Campaigns.CampaignReportScope.append();
    report_request.Scope = scope

    report_columns = reporting_service.factory.create('ArrayOfCampaignPerformanceReportColumn')
    report_columns.CampaignPerformanceReportColumn.append([
        'TimePeriod',
        'CampaignId',
        'CampaignName',
        'DeviceType',
        'Network',
        'Impressions',
        'Clicks',
        'Spend'
    ])
    report_request.Columns = report_columns

    return report_request

我不是很熟悉这些广告数据 APIs,所以任何见解都会有所帮助,即使您没有解决方案。

我花了数周时间与 Microsoft 支持人员来回交流。结果如下:

  1. 您可以通过添加以下代码从示例中获取日志:
import logging

logging.basicConfig(level=logging.INFO)
logging.getLogger('suds.client').setLevel(logging.DEBUG)
logging.getLogger('suds.transport').setLevel(logging.DEBUG)
  1. 问题与示例的构建方式有关。在 auth_helper.py 文件中有一个名为 authenticate 的方法,如下所示:
def authenticate(authorization_data):
    # import logging
    # logging.basicConfig(level=logging.INFO)
    # logging.getLogger('suds.client').setLevel(logging.DEBUG)
    # logging.getLogger('suds.transport.http').setLevel(logging.DEBUG)

    customer_service = ServiceClient(
        service='CustomerManagementService',
        version=13,
        authorization_data=authorization_data,
        environment=ENVIRONMENT,
    )

    # You should authenticate for Bing Ads services with a Microsoft Account.
    authenticate_with_oauth(authorization_data)

    # Set to an empty user identifier to get the current authenticated Bing Ads user,
    # and then search for all accounts the user can access.
    user = get_user_response = customer_service.GetUser(
        UserId=None
    ).User
    accounts = search_accounts_by_user_id(customer_service, user.Id)

    # For this example we'll use the first account.
    authorization_data.account_id = accounts['AdvertiserAccount'][0].Id
    authorization_data.customer_id = accounts['AdvertiserAccount'][0].ParentCustomerId

如您所见,在最底部,它显示“对于此示例,我们将使用第一个帐户。”事实证明,我的公司有 2 个帐户。这在任何地方都不可配置,我不知道这段代码在这里,但您可以在此处添加断点以查看完整的帐户列表。我们只有 2 个,所以我将 0 翻转为 1,一切都开始工作了。