הטמעה: חלוקה לדפים
הדוגמה הבאה מראה איך לאחזר קבוצות נוספות של תוצאות לשאילתות של YouTube Data API (גרסה 3).
ה-API משתמש בפרמטר maxResults
כדי לציין כמה פריטים צריך לכלול בתגובת ה-API. כמעט כל השיטות של list
ב-API (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 ההתאמות הראשונות לשאילתה, וגם את המאפיין nextPageToken
שאפשר להשתמש בו כדי לאחזר את 10 התוצאות הבאות:
השאילתה הבאה מאחזרת את 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
הערה: יכול להיות שתצטרכו לעדכן את הערך של הפרמטר pageToken
כדי להשלים את הבקשה הזו ב-API Explorer. מריצים את השאילתה שמאחזרת את 10 התוצאות הראשונות כדי לקבל את ערך הפרמטר pageToken
הנכון.
אלא אם צוין אחרת, התוכן של דף זה הוא ברישיון Creative Commons Attribution 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"]]