本文介绍了请求报告下载,自定义日期范围在版本12 api中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用python bing sdk下载请求报告,但在api版本11中,我在这些情况下取得了成功:带有自定义日期范围的完整和部分报告。但在版本12中,只有完整报告正在运行。


代码:


def get_campaign_performance_report_request(self):



report_request = self.reporting_service.factory.create('CampaignPerformanceReportRequest')

report_request.ReportName ='bing-ads'

report_request.Format ='Csv'

report_request.ReturnOnlyCompleteData = False

report_request.Aggregation = self.config ['aggregationType']

report_request.Language = self.config ['report_language']
$


scope = self.reporting_service.factory.create('AccountThroughCampaignReportScope' )b


scope.AccountIds = {'long':[s elf.config ['accountId']]}

scope.Campaigns =无

report_request.Scope = scope

report_time = self.reporting_service.factory。 create('ReportTime')



如果不是self.config ['full']:

report_time.ReportTimeZone ='Brasilia'

report_time.PredefinedTime ='昨天'



其他:

custom_date_range_start = self.reporting_service.factory.create('Date')

custom_date_range_start.Day = int(self.config ['start_date'] [8:10])

custom_date_range_start.Month = int(self.config ['start_date'] [5:7])

custom_date_range_start.Year = int(self.config ['start_date'] [:4])

report_time.CustomDateRangeStart = custom_date_range_start



custom_date_range_end = self.reporting_service.factory.create ('日期')

custom_date_range_end.Day = int(self.config ['end_date'] [8:10])

custom_date_range_end.Month = int(self.config ['end_date'] [5:7])

custom_date_range_end.Year = int(self.config ['end_date'] [:4])

report_time.CustomDateRangeEnd = custom_date_range_end



report_time.PredefinedTime =无



report_request.Time = report_time



report_columns=self.reporting_service.factory.create('ArrayOfCampaignPerformanceReportColumn')

report_columns.CampaignPerformanceReportColumn.append([



'CampaignName',#Campaign



'展示次数',#Impressões



'点击',#Cliques



'花',#Custo



'AveragePosition',#Pos。 méd



'ImpressionSharePercent',#Parcela de impr。 Da rede de pesquisa



'ImpressionLostToBudgetPercent',#Parc impr perd Pesquisa(orc) 



'ImpressionLostToRankPercent',#Parc impr perd Pesquisa(class)



'收入',#Receita



'DeviceType',#Tipo de Campanha



'ConversionRate',#tax deconversão



'转化',#numero deconversão



'ReturnOnAdSpend',#ROI - Retorno do invertimento



'TimePeriod'

])



report_request.Columns = report_columns



print(report_request)



返回report_request


XML:


<?xml version =" 1.0" encoding =" UTF-8"?>
$
< SOAP-ENV:Envelope xmlns:SOAP-ENV =" http://schemas.xmlsoap.org/soap/envelope/"的xmlns:NS0 = QUOT; HTTPS://bingads.microsoft.com/Reporting/v12"的xmlns:NS1 = QUOT; HTTP://schemas.xmlsoap.org/soap/envelope/"的xmlns:ns2的= QUOT; HTTP://schemas.microsoft.com/2003/10/Serialization/Arrays"
xmlns:tns =" https://guideads.microsoft.com/Reporting/v12" xmlns:xsi =" http://www.w3.org/2001/XMLSchema-instance">

< SOAP-ENV:标题>

< tns:AuthenticationToken> ***< / tns:AuthenticationToken>


< tns:CustomerAccountId> ***< / tns:CustomerAccountId>

< tns:CustomerId> ***< / tns:CustomerId>

< tns:DeveloperToken> ***< / tns:DeveloperToken>

< / SOAP-ENV:Header>

< ns1:正文>

< ns0:SubmitGenerateReportRequest>

< ns0:ReportRequest xsi:type =" ns0:CampaignPerformanceReportRequest">

< ns0:格式> Csv< / ns0:格式>

< ns0:语言>英文< / ns0:语言>

< ns0:ReportName> 20180501_bing-ads< / ns0:ReportName>

< ns0:ReturnOnlyCompleteData> false< / ns0:ReturnOnlyCompleteData>

< ns0:聚合>每日< / ns0:聚合>

< ns0:列>

< ns0:CampaignPerformanceReportColumn> CampaignName< / ns0:CampaignPerformanceReportColumn>

< ns0:CampaignPerformanceReportColumn> Impressions< ; / ns0:CampaignPerformanceReportColumn>

< ns0:CampaignPerformanceReportColumn> Clicks< / ns0:CampaignPerformanceReportColumn>

< ns0:CampaignPer formanceReportColumn>花费< / ns0:CampaignPerformanceReportColumn>

< ns0:CampaignPerformanceReportColumn> AveragePosition< / ns0:CampaignPerformanceReportColumn>


< ns0:CampaignPerformanceReportColumn> ImpressionSharePercent< / ns0:CampaignPerformanceReportColumn>

< ns0:CampaignPerformanceReportColumn> ImpressionLostToBudgetPercent< / ns0:CampaignPerformanceReportColumn>

< ns0:CampaignPerformanceReportColumn> ImpressionLostToRankPercent< / ns0:CampaignPerformanceReportColumn>

< ns0:CampaignPerformanceReportColumn>收入< / ns0:CampaignPerformanceReportColumn>

< ns0:CampaignPerformanceReportColumn> DeviceType< / ns0:CampaignPerformanceReportColumn>

< ns0:CampaignPerformanceReportColumn> ConversionRate< / ns0:CampaignPerformanceReportColumn>

< ns0:CampaignPerformanceReportColumn>转化< / ns0:CampaignPerformanceReportColumn>

< ns0:CampaignPerformanceReportColumn> ReturnOnAdSpend< ; / ns0:CampaignPerformanceReportColumn>

< ns0:CampaignPerformanceReportColumn> TimePeriod< / ns0:CampaignPerformanceReportColumn>

< / ns0:Columns>

< ns0:范围>

< ns0:AccountIds>

< ns2:long> ***< / ns2:long>

< / ns0:AccountIds>

< / ns0:Sc打开> b
< ns0:时间>

< ns0:CustomDateRangeEnd>

< ns0:Day> 25< / ns0:Day>

< ns0:Month> 5< / ns0:Month>

< ns0:Year> 2018< / ns0:Year>

< / ns0:CustomDateRangeEnd>

< ns0:CustomDateRangeStart>

< ns0:Day> 1< / ns0:Day>

< ns0:Month> ; 5< / ns0:Month>

< ns0:Year> 2018< / ns0:Year>

< / ns0:CustomDateRangeStart>

< ns0:ReportTimeZone />

< / ns0:时间>

< / ns0:ReportRequest>

< / ns0:SubmitGenerateReportRequest>

< / ns1:Body>

< / SOAP-ENV:Envelope>


响应错误:


< s:Envelope xmlns:s =" http://schemas.xmlsoap.org/soap/envelope/">

< s:Body>

< s :故障>

< faultcode xmlns:a =" http://schemas.microsoft.com/net/2005/ 12 / windowscommunicationfoundation / dispatcher"> a:DeserializationFailed< / faultcode>

< faultstring xml:lang =" en- US">格式化程序在尝试反序列化消息时抛出异常:尝试反序列化参数时出错https://bingads.microsoft.com/Reporting/v12:ReportRequest。
InnerException消息是\'无效的枚举值\'\'无法反序列化为类型\'Microsoft.AdCenter.Advertiser.Reporting.Api.DataContracts.Enum.ReportTimeZone \'。确保存在必要的枚举值,并且如果类型具有DataContractAttribute属性,则使用EnumMemberAttribute
属性标记。\'。 有关详细信息,请参阅InnerException。< / faultstring>

< / s:故障>

< / s:Body>

< / s:Envelope>






$

解决方案

i'm trying to make a request report download with python bing sdk, but in api version 11 i've got success in these cases: full and partial report with custom date range. But in version 12 only full report is working.

Code:

def get_campaign_performance_report_request(self):

report_request=self.reporting_service.factory.create('CampaignPerformanceReportRequest')
report_request.ReportName='bing-ads'
report_request.Format='Csv'
report_request.ReturnOnlyCompleteData=False
report_request.Aggregation=self.config['aggregationType']
report_request.Language=self.config['report_language']

scope = self.reporting_service.factory.create('AccountThroughCampaignReportScope')

scope.AccountIds={'long':[self.config['accountId']]}
scope.Campaigns=None
report_request.Scope=scope
report_time= self.reporting_service.factory.create('ReportTime')

if not self.config['full']:
report_time.ReportTimeZone = 'Brasilia'
report_time.PredefinedTime='Yesterday'

else:
custom_date_range_start=self.reporting_service.factory.create('Date')
custom_date_range_start.Day=int(self.config['start_date'][8:10])
custom_date_range_start.Month=int(self.config['start_date'][5:7])
custom_date_range_start.Year=int(self.config['start_date'][:4])
report_time.CustomDateRangeStart = custom_date_range_start

custom_date_range_end=self.reporting_service.factory.create('Date')
custom_date_range_end.Day=int(self.config['end_date'][8:10])
custom_date_range_end.Month=int(self.config['end_date'][5:7])
custom_date_range_end.Year=int(self.config['end_date'][:4])
report_time.CustomDateRangeEnd = custom_date_range_end

report_time.PredefinedTime = None

report_request.Time=report_time

report_columns=self.reporting_service.factory.create('ArrayOfCampaignPerformanceReportColumn')
report_columns.CampaignPerformanceReportColumn.append([

'CampaignName', #Campaign

'Impressions', #Impressões

'Clicks', #Cliques

'Spend', #Custo

'AveragePosition', #Pos. méd

'ImpressionSharePercent',#Parcela de impr. Da rede de pesquisa

'ImpressionLostToBudgetPercent', #Parc impr perd Pesquisa (orc) 

'ImpressionLostToRankPercent', #Parc impr perd Pesquisa(class)

'Revenue', #Receita

'DeviceType', #Tipo de Campanha

'ConversionRate', #taxa de conversão

'Conversions',#numero de conversão

'ReturnOnAdSpend', #ROI - Retorno do invertimento

'TimePeriod'
])

report_request.Columns=report_columns

print(report_request)

return report_request

XML:

<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns0="https://bingads.microsoft.com/Reporting/v12" xmlns:ns1="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns2="http://schemas.microsoft.com/2003/10/Serialization/Arrays" xmlns:tns="https://bingads.microsoft.com/Reporting/v12" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<SOAP-ENV:Header>
<tns:AuthenticationToken>***</tns:AuthenticationToken>
<tns:CustomerAccountId>***</tns:CustomerAccountId>
<tns:CustomerId>***</tns:CustomerId>
<tns:DeveloperToken>***</tns:DeveloperToken>
</SOAP-ENV:Header>
<ns1:Body>
<ns0:SubmitGenerateReportRequest>
<ns0:ReportRequest xsi:type="ns0:CampaignPerformanceReportRequest">
<ns0:Format>Csv</ns0:Format>
<ns0:Language>English</ns0:Language>
<ns0:ReportName>20180501_bing-ads</ns0:ReportName>
<ns0:ReturnOnlyCompleteData>false</ns0:ReturnOnlyCompleteData>
<ns0:Aggregation>Daily</ns0:Aggregation>
<ns0:Columns>
<ns0:CampaignPerformanceReportColumn>CampaignName</ns0:CampaignPerformanceReportColumn>
<ns0:CampaignPerformanceReportColumn>Impressions</ns0:CampaignPerformanceReportColumn>
<ns0:CampaignPerformanceReportColumn>Clicks</ns0:CampaignPerformanceReportColumn>
<ns0:CampaignPerformanceReportColumn>Spend</ns0:CampaignPerformanceReportColumn>
<ns0:CampaignPerformanceReportColumn>AveragePosition</ns0:CampaignPerformanceReportColumn>
<ns0:CampaignPerformanceReportColumn>ImpressionSharePercent</ns0:CampaignPerformanceReportColumn>
<ns0:CampaignPerformanceReportColumn>ImpressionLostToBudgetPercent</ns0:CampaignPerformanceReportColumn>
<ns0:CampaignPerformanceReportColumn>ImpressionLostToRankPercent</ns0:CampaignPerformanceReportColumn>
<ns0:CampaignPerformanceReportColumn>Revenue</ns0:CampaignPerformanceReportColumn>
<ns0:CampaignPerformanceReportColumn>DeviceType</ns0:CampaignPerformanceReportColumn>
<ns0:CampaignPerformanceReportColumn>ConversionRate</ns0:CampaignPerformanceReportColumn>
<ns0:CampaignPerformanceReportColumn>Conversions</ns0:CampaignPerformanceReportColumn>
<ns0:CampaignPerformanceReportColumn>ReturnOnAdSpend</ns0:CampaignPerformanceReportColumn>
<ns0:CampaignPerformanceReportColumn>TimePeriod</ns0:CampaignPerformanceReportColumn>
</ns0:Columns>
<ns0:Scope>
<ns0:AccountIds>
<ns2:long>***</ns2:long>
</ns0:AccountIds>
</ns0:Scope>
<ns0:Time>
<ns0:CustomDateRangeEnd>
<ns0:Day>25</ns0:Day>
<ns0:Month>5</ns0:Month>
<ns0:Year>2018</ns0:Year>
</ns0:CustomDateRangeEnd>
<ns0:CustomDateRangeStart>
<ns0:Day>1</ns0:Day>
<ns0:Month>5</ns0:Month>
<ns0:Year>2018</ns0:Year>
</ns0:CustomDateRangeStart>
<ns0:ReportTimeZone/>
</ns0:Time>
</ns0:ReportRequest>
</ns0:SubmitGenerateReportRequest>
</ns1:Body>
</SOAP-ENV:Envelope>

Response Error:

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Body>
<s:Fault>
<faultcode xmlns:a="http://schemas.microsoft.com/net/2005/12/windowscommunicationfoundation/dispatcher">a:DeserializationFailed</faultcode>
<faultstring xml:lang="en-US">The formatter threw an exception while trying to deserialize the message: There was an error while trying to deserialize parameter https://bingads.microsoft.com/Reporting/v12:ReportRequest. The InnerException message was \'Invalid enum value \'\' cannot be deserialized into type \'Microsoft.AdCenter.Advertiser.Reporting.Api.DataContracts.Enum.ReportTimeZone\'. Ensure that the necessary enum values are present and are marked with EnumMemberAttribute attribute if the type has DataContractAttribute attribute.\'.  Please see InnerException for more details.</faultstring>
</s:Fault>
</s:Body>
</s:Envelope>

解决方案


这篇关于请求报告下载,自定义日期范围在版本12 api中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-09 21:00