実装: ページ分け
次の例は、YouTube Data API(v3)クエリの追加の結果セットを取得する方法を示しています。
この API は、maxResults
パラメータを使用して、API レスポンスに含めるアイテムの数を示します。API の list
メソッドのほとんど(videos.list
、playlists.list
など)がこのパラメータをサポートしています。
クエリで追加の結果が利用可能な場合、API レスポンスには nextPageToken
プロパティ、prevPageToken
プロパティ、またはその両方が含まれます。これらのプロパティの値を使用して、pageToken
パラメータを設定し、結果の追加ページを取得できます。
たとえば、次のクエリは、クエリ「スケートボード ドッグ」に一致する視聴回数が最も多い 10 本の動画の検索結果を取得します。
https://developers.google.com/apis-explorer/#p/youtube/v3/youtube.search.list?
part=snippet
&maxResults=10
&order=viewCount
&q=skateboarding+dog
&type=video
API レスポンスには、クエリの最初の 10 件の一致と、次の 10 件の結果を取得するために使用できる nextPageToken
プロパティが含まれます。
次のクエリは、クエリの次の 10 件の結果を取得します。
https://developers.google.com/apis-explorer/#p/youtube/v3/youtube.search.list?
part=snippet
&maxResults=10
&order=viewCount
&pageToken=CAoQAA
&q=skateboarding+dog
&type=video
注: API Explorer でこのリクエストを完了するには、pageToken
パラメータの値を更新しなければならない場合があります。最初の 10 件の結果を取得するクエリを実行して、正しい pageToken
パラメータ値を取得します。
特に記載のない限り、このページのコンテンツはクリエイティブ・コモンズの表示 4.0 ライセンスにより使用許諾されます。コードサンプルは Apache 2.0 ライセンスにより使用許諾されます。詳しくは、Google Developers サイトのポリシーをご覧ください。Java は Oracle および関連会社の登録商標です。
最終更新日 2024-11-23 UTC。
[null,null,["最終更新日 2024-11-23 UTC。"],[[["The YouTube Data API (v3) uses the `maxResults` parameter to determine the number of items returned in a query response."],["API `list` methods, such as `videos.list` and `playlists.list`, support the `maxResults` parameter for pagination."],["If more results are available, the API response includes `nextPageToken` and/or `prevPageToken` properties."],["These token values can be used to set the `pageToken` parameter to retrieve additional result pages."],["The initial request fetches the first page of results, and subsequent requests use the `pageToken` from the previous response to get the next page of results."]]],["The YouTube Data API (v3) uses `maxResults` to specify the number of items in a response. `list` methods support this, and responses with additional results include `nextPageToken` or `prevPageToken`. These tokens, used with the `pageToken` parameter, retrieve further result sets. For instance, a query can get 10 most viewed videos, and a `nextPageToken` in the response allows fetching the next 10 by adding this value in the `pageToken` parameter.\n"]]