36

我正在尝试使用此示例从 YouTube API (v3) 获取视频数据:

https://developers.google.com/apis-explorer/#p/youtube/v3/youtube.search.list?part=snippet&maxResults=25&order=relevance&q=site%253Ayoutube.com&topicId=%252Fm%252F02vx4&_h=1&

问题是我不明白如何更改页面结果。例如,这个查询给了我 25 个项目 (maxResults=25) 但总结果是 --> "totalResults": 548669。所以这里的大问题是如何移动到第 2 页并接收其他 25 个结果?

4

2 回答 2

77

If you look at the results, you will see a "nextPageToken" item right after "pageInfo". This needs to be passed as the pageToken on your next request.

So if you make a call to this api:

https://www.googleapis.com/youtube/v3/search?part=snippet&maxResults=25&order=relevance&q=site%3Ayoutube.com&topicId=%2Fm%2F02vx4&key={YOUR_API_KEY}

You would make a call to this one for the next page:

https://www.googleapis.com/youtube/v3/search?pageToken=CBkQAA&part=snippet&maxResults=25&order=relevance&q=site%3Ayoutube.com&topicId=%2Fm%2F02vx4&key={YOUR_API_KEY}
于 2013-01-28T18:46:47.957 回答
6

例如这是你的 api

https://www.googleapis.com/youtube/v3/playlists?part=snippet,contentDetails&channelId=UCrA&maxResults=50&key=AIZsk

在这里使用这个 api 你会得到类似的结果

{
"kind": "youtube#playlistListResponse",
"etag": "\"XpPGQXPLgenD_n8JR4Qk/05DoUs3OS-AxnDI1FJbdM\"",
"nextPageToken": "CDIQAA",
"pageInfo": {
    "totalResults": 585,
    "resultsPerPage": 50
},
"items": [
    {
        "kind": "youtube#playlist",
        "etag": "\"XpPGQXPLgenD_n8JR4Qk/7m0ztlwxvPmRtXjs\"",
        .........
        .........

在此结果中,请参阅“nextPageToken”:“CDIQAA”,

现在将pageToken参数添加到您的 api

前任:

https://www.googleapis.com/youtube/v3/playlists?part=snippet,contentDetails&channelId=UCqrA&maxResults=50&key=AIZsk&pageToken=CDIQAA

现在这是您的结果,您将获得 nextPageToken 和 prevPageToken

{
"kind": "youtube#playlistListResponse",
"etag": "\"XpPGQX4Qk/R3A6jpxuE\"",
"nextPageToken": "CGQQAA",
"prevPageToken": "CDIQAQ",
"pageInfo": {
    "totalResults": 585,
    "resultsPerPage": 50
},
"items": [
    {
        "kind": "youtube#playlist",
        "etag": "\"XpPGQXR4Qk/XsatNRtxJQ\"",

        .........
        .........
于 2019-03-19T11:33:08.583 回答