Uygulama: Sayfalara ayırma
Aşağıdaki örnekte, YouTube Data API (v3) sorguları için ek sonuç kümelerinin nasıl alınacağı gösterilmektedir.
API, bir API yanıtına kaç öğe ekleneceğini belirtmek için maxResults
parametresini kullanır. API'nin list
yöntemlerinin (videos.list
, playlists.list
vb.) neredeyse tamamı bu parametreyi destekler.
Bir sorgu için ek sonuçlar varsa API yanıtı bir nextPageToken
mülkü, bir prevPageToken
mülkü veya her ikisi de içerir. Bu özelliklerin değerleri daha sonra pageToken
parametresini ek bir sonuç sayfası almak için ayarlamak üzere kullanılabilir.
Örneğin, aşağıdaki sorgu "skateboarding dog" (kaykay yapan köpek) sorgusuyla eşleşen en çok izlenen 10 videonun arama sonuçlarını getirir:
https://developers.google.com/apis-explorer/#p/youtube/v3/youtube.search.list?
part=snippet
&maxResults=10
&order=viewCount
&q=skateboarding+dog
&type=video
API yanıtı, sorguyla ilgili ilk 10 eşleşmenin yanı sıra sonraki 10 sonucu almak için kullanılabilecek bir nextPageToken
mülkünü içerir:
Aşağıdaki sorgu, sorgu için sonraki 10 sonucu alır:
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
Not: Bu isteği API Gezgini'nde tamamlamak için pageToken
parametresinin değerini güncellemeniz gerekebilir. Doğru pageToken
parametre değerini almak için ilk 10 sonucu döndüren sorguyu yürütün.
Aksi belirtilmediği sürece bu sayfanın içeriği Creative Commons Atıf 4.0 Lisansı altında ve kod örnekleri Apache 2.0 Lisansı altında lisanslanmıştır. Ayrıntılı bilgi için Google Developers Site Politikaları'na göz atın. Java, Oracle ve/veya satış ortaklarının tescilli ticari markasıdır.
Son güncelleme tarihi: 2024-11-23 UTC.
[null,null,["Son güncelleme tarihi: 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"]]