我可以以某种方式限制json对象返回的节点数量?我只使用每个搜索结果中的标题,作者和视频ID,因此我无需加载和解析其他一百万个节点.无论如何这样做除了运行它以为服务器端代理? 最佳答案 不确定为什么每个人都说不,因为虽然你不能将它限制为JUST title,channelId和videoId,但你可以选择保留一些字段.您可以在Data Api的v3中使用“fields”参数.
Check out the documentation here.
没有设置字段的响应:
{
"kind": "youtube#searchListResponse",
"etag": "\"a6IVtoIjS7Yw-1cFQOGQ6_bjjs4/_DFSOhdxHuGG_p_f1fVZOosZghs\"",
"pageInfo": {
"totalResults": 1000000,
"resultsPerPage": 2
},
"nextPageToken": "CAIQAA",
"items": [
{
"id": {
"kind": "youtube#video",
"videoId": "dw1HavgoK9E"
},
"kind": "youtube#searchResult",
"etag": "\"a6IVtoIjS7Yw-1cFQOGQ6_bjjs4/aY_GfDmiGidcZL_TBO7vI8YP9XY\"",
"snippet": {
"publishedAt": "2013-02-15T09:38:27.000Z",
"channelId": "UCvZuIe7j7oBfaWAL0sO3JzQ",
"title": "Drivers stoned on marijuana test their driving skills",
"description": "If you watched this video and liked Addy, you can watch outtakes of her here: http://kiro.tv/WFNEMZ CNN may have just posted their best piece of investigativ...",
"thumbnails": {
"default": {
"url": "https://i.ytimg.com/vi/dw1HavgoK9E/default.jpg"
},
"medium": {
"url": "https://i.ytimg.com/vi/dw1HavgoK9E/mqdefault.jpg"
},
"high": {
"url": "https://i.ytimg.com/vi/dw1HavgoK9E/hqdefault.jpg"
}
}
}
}
}
设置字段的响应:
{
"items": [
{
"id": {
"kind": "youtube#video",
"videoId": "dw1HavgoK9E"
},
"snippet": {
"publishedAt": "2013-02-15T09:38:27.000Z",
"channelId": "UCvZuIe7j7oBfaWAL0sO3JzQ",
"title": "Drivers stoned on marijuana test their driving skills",
"description": "If you watched this video and liked Addy, you can watch outtakes of her here: http://kiro.tv/WFNEMZ CNN may have just posted their best piece of investigativ...",
"thumbnails": {
"default": {
"url": "https://i.ytimg.com/vi/dw1HavgoK9E/default.jpg"
},
"medium": {
"url": "https://i.ytimg.com/vi/dw1HavgoK9E/mqdefault.jpg"
},
"high": {
"url": "https://i.ytimg.com/vi/dw1HavgoK9E/hqdefault.jpg"
}
}
}
}
}