Batch
コレクションでコンテンツを整理
必要に応じて、コンテンツの保存と分類を行います。
互換性のないディメンションと指標を使用している場合や、異なる方法でデータを集計する場合などは、必要な情報をすべて 1 つのレポートから得ることができない場合があります。
このような場合は、複数のレポートを作成する必要があります。
また、バッチ処理は、リクエスト数を減らしてアプリのパフォーマンスを改善する効果的な方法です。
複数の独立したリクエストを行う場合の問題
実装はシンプルな解決策ですが、短時間で複数の API リクエストを行うと、割り当て制限に達する場合があります。
より優れた解決策は、並列リクエストを完全に避け、代わりにバッチ リクエストを作成することです。
レポートのバッチ処理
ユーザー主導のアプリケーションの例では、最初のアプローチは、独立したリクエストをできるだけ多く 1 つのバッチ リクエストにまとめることです。
レポート 1: 8 月の上位 10 か国
レポート 2: 7 月の上位 10 か国の値(比較用)
レポート 3: 8 月の上位 10 チャンネル
レポート 4: 7 月の上位 10 チャンネルの値(比較用)
上の例では、レポート 1 と 3 はそれぞれ独立していますが、データの内訳が異なるため、1 つのレポートにまとめることはできません。ただし、まとめてバッチ処理することはできます。
レポート 2 と 4 は、リクエストに適切なフィルタを設定する必要があるため、最初のバッチで結果を取得した後でのみ実行できます。最初のバッチの結果が届いたら、これを 2 番目のバッチとして実行できます。
すべてのリクエストを 1 つのバッチにまとめる別のオプションとして、上位 10 件だけではなく 7 月のすべての値を返し、場合によっては 8 月もすべて返します。問題の AdSense アカウントの規模やアプリケーションで使用可能なメモリ量によっては、この方法が妥当な場合もあります。
仕組み
バッチ処理の処理方法はクライアント ライブラリごとに異なるため、詳細はクライアント ライブラリのドキュメントをご覧ください。いくつかのクライアント ライブラリの関連ドキュメントへのリンクを以下に示します。
次のステップ
特に記載のない限り、このページのコンテンツはクリエイティブ・コモンズの表示 4.0 ライセンスにより使用許諾されます。コードサンプルは Apache 2.0 ライセンスにより使用許諾されます。詳しくは、Google Developers サイトのポリシーをご覧ください。Java は Oracle および関連会社の登録商標です。
最終更新日 2025-07-26 UTC。
[null,null,["最終更新日 2025-07-26 UTC。"],[[["\u003cp\u003eBatching requests improves app performance by reducing the number of API calls and mitigating quota limitations.\u003c/p\u003e\n"],["\u003cp\u003eIndependent reports, like those with incompatible dimensions or metrics, can be combined into batch requests.\u003c/p\u003e\n"],["\u003cp\u003eBatching can involve grouping related reports or retrieving broader data sets to minimize the total number of batches.\u003c/p\u003e\n"],["\u003cp\u003eSpecific batching implementations vary by client library (.NET, PHP, Python, Java, Ruby, etc.).\u003c/p\u003e\n"],["\u003cp\u003eFor handling very large reports or incompatible dimensions and metrics, refer to the provided resources for further guidance.\u003c/p\u003e\n"]]],["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"],null,["# Batch\n\nSometimes it's not possible to get all the information you need out of a single report, such as when you have incompatible dimensions and metrics, or when you're looking to aggregate data in different ways.\n\nIn those situations, you'll need to run multiple reports.\n\nAlso, batching is an effective way to improve your app's performance, reducing the number of requests.\n\nThe problem with making multiple independent requests\n-----------------------------------------------------\n\nWhile a simple solution to implement, making multiple API requests in a short amount of time may cause you to run into quota limitations.\n\nA better solution is to avoid the parallel requests altogether, and instead create batch requests.\n\nReport batching\n---------------\n\nIn the example of a user-driven application, a first approach would be to combine as many independent requests as possible into a single batch request.\n\n\n**Report 1:** Top 10 countries for August \n\n**Report 2:** Values for same 10 countries in July, for comparison \n\n**Report 3:** Top 10 channels for August \n\n**Report 4:** Values for same 10 channels in July, for comparison\n\nIn the above example, reports 1 and 3 are independent, but cannot be combined into a single report, since they offer different breakdowns of the data. They can, however, be batched together.\n\nReports 2 and 4 can only be run after obtaining the results of the first batch, since we need to set up an appropriate filter in the request. These can be run as a second batch, once the results from the first arrive.\n\nA different option, which would allow all requests to be combined into a single batch, would be to simply return all values for July (instead of just the top 10), and potentially August as well. This may be a reasonable option depending on the size of the AdSense account in question and the amount of memory available to your application.\n\nHow it's done\n-------------\n\nBatching is handled differently in each client library, so you should check its documentation in order to find out the details. Here are some links to the relevant documentation in several client libraries:\n\n- [.NET](https://developers.google.com/api-client-library/dotnet/guide/batch)\n- [PHP](https://developers.google.com/api-client-library/php/guide/batch)\n- [Python](https://developers.google.com/api-client-library/python/guide/batch)\n- [Java](https://code.google.com/p/google-api-java-client/wiki/Batch)\n- [Ruby](https://developers.google.com/api-client-library/ruby/guide/batch)\n\n\u003cbr /\u003e\n\nNext steps\n----------\n\n- [Running Large Reports](/adsense/management/reporting/large_reports)\n- [Incompatible Dimensions and Metrics](/adsense/management/reporting/dimensions_metrics#incompatible)"]]