我能以某种方式限制json对象返回的节点数量吗?我只使用每个搜索结果中的标题、作者和视频id,因此不需要加载和解析一百万个其他节点。无论如何做这个除了运行它认为一个服务器端代理?
不知道为什么每个人都说不,因为虽然你不能限制它只是title, channelId和videoId,你可以选择离开一些字段。有一个"fields"参数可以在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"
}
}
}
}
}
API调用:https://www.googleapis.com/youtube/v3/search?part=id%2Csnippet&maxResults=1&q=test&key={YOUR_API_KEY}
响应字段设置:
{
"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"
}
}
}
}
}
API调用:https://www.googleapis.com/youtube/v3/search?part=id%2Csnippet&maxResults=1&q=test&fields=items(id%2Csnippet)&key={YOUR_API_KEY}
没有。通过代理似乎不是个好主意。如果你只是在想,我在浪费时间,我们把它砍掉吧,那你就不能。div;)