我可以以某种方式限制 json 对象返回的节点数量吗?我只使用每个搜索结果中的标题、作者和视频 ID,所以我不需要加载和解析一百万个其他节点。无论如何,除了运行它认为服务器端代理之外,还要这样做吗?
问问题
404 次
2 回答
2
不知道为什么每个人都说不,因为虽然您不能将其限制为 JUST title、channelId 和 videoId,但您可以选择省略一些字段。您可以在 Data Api 的 v3 中使用“字段”参数。 在此处查看文档。
未设置字段的响应:
{
"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"
}
}
}
}
}
于 2013-03-02T02:13:37.237 回答
0
没有。通过代理似乎不是一个好主意。如果你只是在想,我在浪费带宽,让我们削减它,那么你不能。;)
于 2013-03-01T22:16:55.437 回答