成批
有时,您无法从单个报告中获取所需的所有信息,例如当您的维度和指标不兼容时,或者您希望以不同的方式汇总数据时。
在此类情况下,您需要生成多个报告。
此外,批处理还可以减少请求数量,也是提高应用性能的有效方式。
发出多个独立请求的问题
虽然这是一个简单的实施解决方案,但在短时间内发出多个 API 请求可能会导致您遇到配额限制。
更好的解决方案是完全避免并行请求,而改为创建批量请求。
报告批量处理
在由用户驱动的应用示例中,第一种方法是将尽可能多的独立请求合并为一个批量请求。
报告 1:8 月份排名前 10 的国家/地区
报告 2:这 10 个国家/地区在 7 月份的值(进行对比)
报告 3:8 月份排名前 10 的渠道
报告 4:这 10 个渠道在 7 月份的值(进行对比)
在上述示例中,报告 1 和报告 3 是独立的,但无法合并为一份报告,因为它们提供的数据细分方式不同。不过,可以将它们一起批量处理。
只有在获得第一批结果后,才能生成报告 2 和报告 4,因为我们需要在请求中设置相应的过滤器。一旦第一批结果到达,这些作业可以作为第二批运行。
另一个方法是将所有请求合并到一个批次中,那就是直接返回 7 月的所有值(而不仅仅是前 10 个值),还可能返回 8 月的所有值。这可能是一个合理的选择,具体取决于相关 AdSense 帐号的大小以及您的应用可用的内存大小。
具体做法
批处理在每个客户端库中的处理方式不同,因此您应查看其文档以了解详情。以下是多个客户端库中相关文档的链接:
后续步骤
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2024-08-22。
[null,null,["最后更新时间 (UTC):2024-08-22。"],[[["Batching requests improves app performance by reducing the number of API calls and mitigating quota limitations."],["Independent reports, like those with incompatible dimensions or metrics, can be combined into batch requests."],["Batching can involve grouping related reports or retrieving broader data sets to minimize the total number of batches."],["Specific batching implementations vary by client library (.NET, PHP, Python, Java, Ruby, etc.)."],["For handling very large reports or incompatible dimensions and metrics, refer to the provided resources for further guidance."]]],["When single reports can't provide all necessary data due to incompatible dimensions or different aggregation needs, multiple reports are required. Batching multiple API requests improves app performance and reduces quota limitations, avoiding parallel requests. Independent requests, like retrieving top countries and channels, can be combined into a single batch. Subsequent requests for comparison data can be batched afterward, once the initial batch results are available. Client libraries offer varied methods for batching, requiring consultation of their respective documentation.\n"]]