通过API在所有广告帐户中下载报告 - python [英] Download report via API across all ad accounts - python

查看:93
本文介绍了通过API在所有广告帐户中下载报告 - python的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好!

我遇到通过Bing广告API提取报告内容的问题。

I am facing issues with report content pulled via Bing ads API.

我关注此代码作为来源:https://msdn.microsoft.com/en-us/library/bing-ads-reporting-request-and-download-a-keyword-performance-report-in-python.aspx

I am following this code as source: https://msdn.microsoft.com/en-us/library/bing-ads-reporting-request-and-download-a-keyword-performance-report-in-python.aspx

目前我只从一个广告帐户获取数据(我有8个):

and at the moment I am only getting data from one ad account (I have 8):

#在这个例子中,我们将使用第一个帐户。

# For this example we'll use the first account.

authorization_data.account_id=accounts['Account'][0].Id authorization_data.customer_id=accounts['Account'][0].ParentCustomerId

如果我尝试循环它只是覆盖以前的广告帐户中的数据。

and if I try to loop it just overwrites the data from the previous ad account.

理想情况下,每次我为每个广告帐户运行代码时都不想附加,因为我将

Ideally I don't want to append every time I run the code for each ad account since I will

有8次(在我的情况下)所有其他报告设置数据默认。

have 8 times(in my case) all the additional report setup data by default.

(报告类型:......等等)。

(Report type: ... and so on).

此外,我正在使用此功能进行报告(目前):

and also, I am using this function for reporting (at the moment):

def get_budget_report_request():

提前谢谢!

Thank you in advance!




推荐答案

您好。

这是很好的反馈,我们会更新样本以澄清。

This is good feedback and we will update the sample to clarify.

1。对于Reporting API,您无需设置CustomerAccountId标头元素(authorization_data.account_id)。 

1. For Reporting API you are not required to set the CustomerAccountId header element (authorization_data.account_id). 

2。您可以使用报表请求"范围"属性来跨多个帐户请求数据。例如,如果您修改

此示例
如下:

2. You can use the report request Scope property to request data across multiple accounts. For example if you modify this sample as follows:

user=customer_service.GetUser(None).User
accounts=search_accounts_by_user_id(user.Id)

# For Reporting API the CustomerAccountId is not required.
# As a best practice you should set it e.g. in case you use
# the same AuthorizationData instance for other services.
# To request data for specific accounts, use the report 
# request scope property.
authorization_data.account_id=accounts['Account'][0].Id
authorization_data.customer_id=accounts['Account'][0].ParentCustomerId
        
account_ids=[]
for account in accounts['Account']:
    account_ids.append(account.Id)
      report_request=get_budget_summary_report_request(account_ids)

然后你可以设置
范围
,用于请求多个帐户ID的数据:

Then you can set the Scope to request data for multiple account IDs:

def get_budget_summary_report_request(account_ids):
    '''
    Build a budget summary report request, including Format, ReportName,
    Time, and Columns.
    '''
    report_request=reporting_service.factory.create('BudgetSummaryReportRequest')
    report_request.Format=REPORT_FILE_FORMAT
    report_request.ReportName='My Budget Summary Report'
    report_request.ReturnOnlyCompleteData=False
    report_request.Language='English'

    scope=reporting_service.factory.create('AccountThroughCampaignReportScope')
    scope.AccountIds={'long': account_ids }
    scope.Campaigns=None
    report_request.Scope=scope




我希望这有帮助!

Eric


这篇关于通过API在所有广告帐户中下载报告 - python的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆