ما در حال بهروزرسانی Data API هستیم تا با نحوه شمارش بازدیدهای YouTube برای Shorts مطابقت داشته باشد.
بیشتر بدانید
پیاده سازی: صفحه بندی
با مجموعهها، منظم بمانید
ذخیره و طبقهبندی محتوا براساس اولویتهای شما.
مثال زیر نحوه بازیابی مجموعههای اضافی از نتایج برای جستارهای YouTube Data API (v3) را نشان میدهد.
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
را برای تکمیل این درخواست در APIs Explorer بهروزرسانی کنید. کوئری را اجرا کنید که 10 نتیجه اول را بازیابی می کند تا مقدار پارامتر pageToken
صحیح را بدست آورید.
جز در مواردی که غیر از این ذکر شده باشد،محتوای این صفحه تحت مجوز Creative Commons Attribution 4.0 License است. نمونه کدها نیز دارای مجوز Apache 2.0 License است. برای اطلاع از جزئیات، به خطمشیهای سایت Google Developers مراجعه کنید. جاوا علامت تجاری ثبتشده Oracle و/یا شرکتهای وابسته به آن است.
تاریخ آخرین بهروزرسانی 2024-11-23 بهوقت ساعت هماهنگ جهانی.
[null,null,["تاریخ آخرین بهروزرسانی 2024-11-23 بهوقت ساعت هماهنگ جهانی."],[[["\u003cp\u003eThe YouTube Data API (v3) uses the \u003ccode\u003emaxResults\u003c/code\u003e parameter to determine the number of items returned in a query response.\u003c/p\u003e\n"],["\u003cp\u003eAPI \u003ccode\u003elist\u003c/code\u003e methods, such as \u003ccode\u003evideos.list\u003c/code\u003e and \u003ccode\u003eplaylists.list\u003c/code\u003e, support the \u003ccode\u003emaxResults\u003c/code\u003e parameter for pagination.\u003c/p\u003e\n"],["\u003cp\u003eIf more results are available, the API response includes \u003ccode\u003enextPageToken\u003c/code\u003e and/or \u003ccode\u003eprevPageToken\u003c/code\u003e properties.\u003c/p\u003e\n"],["\u003cp\u003eThese token values can be used to set the \u003ccode\u003epageToken\u003c/code\u003e parameter to retrieve additional result pages.\u003c/p\u003e\n"],["\u003cp\u003eThe initial request fetches the first page of results, and subsequent requests use the \u003ccode\u003epageToken\u003c/code\u003e from the previous response to get the next page of results.\u003c/p\u003e\n"]]],["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"],null,["# Implementation: Pagination\n\nThe following example shows how to retrieve additional sets of results for YouTube Data API (v3) queries.\n\nThe API uses the `maxResults` parameter to indicate how many items should be included in an API response. Almost all of the API's `list` methods ([videos.list](/youtube/v3/docs/videos/list), [playlists.list](/youtube/v3/docs/playlists/list), etc.) support that parameter.\n\nIf additional results are available for a query, then the API response will contain either a `nextPageToken` property, a `prevPageToken` property, or both. Those properties' values can then be used to set the `pageToken` parameter to retrieve an additional page of results.\n\nFor example, the following query retrieves search results for the 10 most viewed videos matching the query \"skateboarding dog\": \n\n```\nhttps://developers.google.com/apis-explorer/#p/youtube/v3/youtube.search.list?\n part=snippet\n &maxResults=10\n &order=viewCount\n &q=skateboarding+dog\n &type=video\n```\n\nThe API response contains the first 10 matches for the query as well as a `nextPageToken` property that can be used to retrieve the next 10 results:\n\nThe query below retrieves the next 10 results for the query: \n\n```\nhttps://developers.google.com/apis-explorer/#p/youtube/v3/youtube.search.list?\n part=snippet\n &maxResults=10\n &order=viewCount\n &pageToken=CAoQAA\n &q=skateboarding+dog\n &type=video\n```\n\n**Note:** You may need to update the value of the `pageToken` parameter to complete this request in the APIs Explorer. Execute the query that retrieves the first 10 results to obtain the correct `pageToken` parameter value."]]