我正在尝试使用 Microsoft Bing Ads'Reporting API以编程方式收集广告效果数据,例如点击次数、支出等。下面,我将描述所采取的步骤。
问题是,按照这些步骤操作后,我没有得到预期的 SOAP 响应。相反,我得到一个空正文,状态为 HTTP 202 Accepted
。
我正在使用 Postman 来测试服务,我的最终目标是使用 httr
在 R 中执行相同的操作。
身份验证
我关注了他们的OAuth 2.0 Authentication Flow在这方面,我有:
- 注册了我的应用程序(使用开发者帐户)
- 请求用户同意(通过广告帐户)
- 生成了访问 token 和刷新 token
每次访问 API 时,我都会使用刷新 token 生成新的访问 token ,因为访问 token 的生命周期很短。
提出请求
该文档描述了 Reporting Service Operation它遵循异步方法。首先我们需要使用SubmitGenerateReport
向报告服务提出请求。这将返回一个 ResponseRequestId
,然后我们可以使用它来重复轮询服务 PollGenerateReport
直到我们收到所请求的报告作为回应。
提交生成报告
SubmitGenerateReport
必须采用 SOAP XML 格式,如所述 here 。以下是我根据文档中提供的示例为用例生成的文档。
<s:Envelope xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Header xmlns="https://bingads.microsoft.com/Reporting/v13">
<Action mustUnderstand="1">SubmitGenerateReport</Action>
<AuthenticationToken i:nil="false">**AUTHENTICATION_TOKEN_VALUE**</AuthenticationToken>
<CustomerAccountId i:nil="false">**CUSTOMER_ACCOUNT_ID_VALUE**</CustomerAccountId>
<CustomerId i:nil="false">**CUSTOMER_ID_VALUE**</CustomerId>
<DeveloperToken i:nil="false">**DEVELOPER_TOKEN_VALUE**</DeveloperToken>
</s:Header>
<s:Body>
<SubmitGenerateReportRequest xmlns="https://bingads.microsoft.com/Reporting/v13">
<ReportRequest i:nil="false" i:type="-- derived type specified here with the appropriate prefix --">
<ExcludeColumnHeaders i:nil="false">false</ExcludeColumnHeaders>
<ExcludeReportFooter i:nil="false">false</ExcludeReportFooter>
<ExcludeReportHeader i:nil="false">false</ExcludeReportHeader>
<Format i:nil="false">Csv</Format>
<FormatVersion i:nil="false">2.0</FormatVersion>
<ReportName i:nil="false">COA Bing Ad Spend</ReportName>
<ReturnOnlyCompleteData i:nil="false">false</ReturnOnlyCompleteData>
<!--These fields are applicable if the derived type attribute is set to AccountPerformanceReportRequest-->
<Aggregation>Summary</Aggregation>
<Columns i:nil="false">
<AccountPerformanceReportColumn>Spend</AccountPerformanceReportColumn>
</Columns>
<Filter i:nil="false">
<AccountStatus i:nil="false"></AccountStatus>
<AdDistribution i:nil="false"></AdDistribution>
<DeviceOS i:nil="false"></DeviceOS>
<DeviceType i:nil="false"></DeviceType>
</Filter>
<Scope i:nil="false">
<AccountIds i:nil="false" xmlns:a1="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
<a1:long>**ACCOUNT_ID_VALUE**</a1:long>
</AccountIds>
</Scope>
<Time i:nil="false">
<CustomDateRangeEnd i:nil="false">
<Day></Day>
<Month></Month>
<Year></Year>
</CustomDateRangeEnd>
<CustomDateRangeStart i:nil="false">
<Day></Day>
<Month></Month>
<Year></Year>
</CustomDateRangeStart>
<PredefinedTime i:nil="false">ThisWeek</PredefinedTime>
<ReportTimeZone i:nil="false"></ReportTimeZone>
</Time>
</s:Body>
</s:Envelope>
生成此 XML 后,我尝试访问他们的 Reporting Service Endopoint (生产)利用 Postman。
postman 配置
我正在关注this article关于如何使用 Postman 发出 SOAP 请求。
- 我正在向
https://reporting.api.bingads.microsoft.com/Api/Advertiser/Reporting/V13/ReportingService.svc
发出 POST 请求,其中上述 SOAP XML 为 body - 已将正文编码设置为
Raw
- 按照文章中的建议添加了
Content-Type = text/xml
header (将其设置为application/xml
,返回505 内部服务器错误
)
根据文档,我应该得到如下所示的 SOAP 响应:
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Header xmlns="https://bingads.microsoft.com/Reporting/v13">
<TrackingId d3p1:nil="false" xmlns:d3p1="http://www.w3.org/2001/XMLSchema-instance">ValueHere</TrackingId>
</s:Header>
<s:Body>
<SubmitGenerateReportResponse xmlns="https://bingads.microsoft.com/Reporting/v13">
<ReportRequestId d4p1:nil="false" xmlns:d4p1="http://www.w3.org/2001/XMLSchema-instance">ValueHere</ReportRequestId>
</SubmitGenerateReportResponse>
</s:Body>
</s:Envelope>
然后我将使用 ResponseRequestId
轮询服务以获取实际报告。
但是,当我发布此内容时,我收到一个 HTTP 202 Accepted
响应和一个空正文。 Postman 的回复意思是:
The request has been accepted for processing, but the processing has not been completed. The request might or might not eventually be acted upon, as it might be disallowed when the processing actually takes place.
我已多次重做身份验证步骤,并且总体上确信那里没有问题。这让我不知道如何调试它。当我在删除后尝试进行 POST 时(例如身份验证 token 或客户帐户 ID),请求仍然被接受并返回 202。
我以前从未使用过 SOAP API,因此我可能没有遵循正确的流程。任何帮助或指示将不胜感激。
谢谢!
最佳答案
我可以解决这个错误,在搜索了很多页面后,我发现要在 postman 中执行请求,您必须聚合下一个 header 。 header
关于xml - 使用 Bing Ads SOAP API 时如何调试 202 HTTP 状态代码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67404180/