我正在使用Youtube Data API v3来获取视频评论。我按照官方文档https://developers.google.com/youtube/v3/docs/commentThreads/list
使用https://www.googleapis.com/youtube/v3/commentThreads?key=MY_KEY&videoId=ay4MKe1u7Ec&part=id,snippet,replies&maxResults=2
我得到了
{
"kind": "youtube#commentThreadListResponse",
"etag": "\"RmznBCICv9YtgWaaa_nWDIH1_GM/lPy9jihUjGu4N-8qmo83AkMD81E\"",
"nextPageToken": "QURTSl9pMW1lUmhuMHNKaWVDQWhOUUs3UzltVWpEa3JBTW5VdTNQY3I2al9OMmg3VUhUcVRId0lRYkZwV0RiLWdGbG90d3lHQlhzT3dSUnVObmdmaEdpY0RCOGlqRnNUR0pUM05lenpsaVJCUkpFZUFlWDF0SVNyVGFNMURYZ3M=",
"pageInfo": {
"totalResults": 2,
"resultsPerPage": 2
},
"items": [
{
"kind": "youtube#commentThread",
"etag": "\"RmznBCICv9YtgWaaa_nWDIH1_GM/-srkOOUlK2u6VrOhrHLwNvW9uhY\"",
"id": "Ugwud1sVfboCaSWuyR54AaABAg",
"snippet": {
"videoId": "ay4MKe1u7Ec",
"topLevelComment": {
"kind": "youtube#comment",
"etag": "\"RmznBCICv9YtgWaaa_nWDIH1_GM/EdeFN_0T_dycmIDzkqVgskOHm6U\"",
"id": "Ugwud1sVfboCaSWuyR54AaABAg",
"snippet": {
"authorDisplayName": "Gulnaz Saydullaeva",
"authorProfileImageUrl": "https://yt3.ggpht.com/-9jnflsaG9cs/AAAAAAAAAAI/AAAAAAAAAAA/NRge-Hcjxg8/s28-c-k-no-mo-rj-c0xffffff/photo.jpg",
"authorChannelUrl": "http://www.youtube.com/channel/UCKoQIiDBhLNU8cpEMKPfLrQ",
"authorChannelId": {
"value": "UCKoQIiDBhLNU8cpEMKPfLrQ"
},
"videoId": "ay4MKe1u7Ec",
"textDisplay": "А у меня не Android 4. 4. 2 у меня на моём стоит Android 5 0 1",
"textOriginal": "А у меня не Android 4. 4. 2 у меня на моём стоит Android 5 0 1",
"canRate": true,
"viewerRating": "none",
"likeCount": 1,
"publishedAt": "2018-01-22T15:27:39.000Z",
"updatedAt": "2018-01-22T15:27:39.000Z"
}
},
"canReply": true,
"totalReplyCount": 0,
"isPublic": true
}
},
{
"kind": "youtube#commentThread",
"etag": "\"RmznBCICv9YtgWaaa_nWDIH1_GM/Mdis62b6IE0Y3r5zGlGLEDj71pI\"",
"id": "UgxPYBqwH2v_tW2cQjt4AaABAg",
"snippet": {
"videoId": "ay4MKe1u7Ec",
"topLevelComment": {
"kind": "youtube#comment",
"etag": "\"RmznBCICv9YtgWaaa_nWDIH1_GM/manyPQXT2C8CQ66KYtWMWVIUsUI\"",
"id": "UgxPYBqwH2v_tW2cQjt4AaABAg",
"snippet": {
"authorDisplayName": "Gulnaz Saydullaeva",
"authorProfileImageUrl": "https://yt3.ggpht.com/-9jnflsaG9cs/AAAAAAAAAAI/AAAAAAAAAAA/NRge-Hcjxg8/s28-c-k-no-mo-rj-c0xffffff/photo.jpg",
"authorChannelUrl": "http://www.youtube.com/channel/UCKoQIiDBhLNU8cpEMKPfLrQ",
"authorChannelId": {
"value": "UCKoQIiDBhLNU8cpEMKPfLrQ"
},
"videoId": "ay4MKe1u7Ec",
"textDisplay": "У меня такой же не lte",
"textOriginal": "У меня такой же не lte",
"canRate": true,
"viewerRating": "none",
"likeCount": 0,
"publishedAt": "2018-01-16T13:32:26.000Z",
"updatedAt": "2018-01-16T13:32:26.000Z"
}
},
"canReply": true,
"totalReplyCount": 0,
"isPublic": true
}
}
]
}
在items
这里我得到很多字段作为回应,我对所有领域都不感兴趣。所以试图在网址中添加fields
param
https://www.googleapis.com/youtube/v3/commentThreads?key=MY_KEY&videoId=ay4MKe1u7Ec&part=id,snippet,replies&fields=items(id,snippet(topLevelComment(snippet(textOriginal))))&maxResults=2
然后我只获得了所需的字段但是没有nextPageToken
没有它我不能转到下一页。
{
"items": [
{
"id": "Ugwud1sVfboCaSWuyR54AaABAg",
"snippet": {
"topLevelComment": {
"snippet": {
"textOriginal": "А у меня не Android 4. 4. 2 у меня на моём стоит Android 5 0 1"
}
}
}
},
{
"id": "UgxPYBqwH2v_tW2cQjt4AaABAg",
"snippet": {
"topLevelComment": {
"snippet": {
"textOriginal": "У меня такой же не lte"
}
}
}
}
]
}
我使用简单的python脚本调用URL
import requests
url = 'https://www.googleapis.com/youtube/v3/commentThreads'
params = {'key': API_KEY,
'videoId': 'ay4MKe1u7Ec',
'part': 'id,snippet,replies',
'maxResults': 2,
'fields': 'items(id,snippet(topLevelComment(snippet(textOriginal))))'}
r = requests.get(url, params=params)
print(r.json())
我不知道为什么我yuotube api没有给我使用字段参数nextPageToken。有人请告诉我如果错误地使用API。