การใช้งาน: การใส่เลขหน้า
ตัวอย่างต่อไปนี้แสดงวิธีเรียกชุดผลลัพธ์เพิ่มเติมสำหรับการค้นหาของ YouTube Data API (v3)
API ใช้พารามิเตอร์ maxResults
เพื่อระบุจํานวนรายการที่ควรรวมไว้ในคําตอบของ API เมธอด list
เกือบทั้งหมดของ API (videos.list
, playlists.list
ฯลฯ) รองรับพารามิเตอร์ดังกล่าว
หากการค้นหามีผลการค้นหาเพิ่มเติม การตอบกลับของ API จะมีพร็อพเพอร์ตี้ nextPageToken
, พร็อพเพอร์ตี้ prevPageToken
หรือทั้ง 2 อย่าง จากนั้นจะใช้ค่าของพร็อพเพอร์ตี้เหล่านั้นเพื่อตั้งค่าพารามิเตอร์ 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 เรียกใช้การค้นหาที่ดึงข้อมูล 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"]]