我想使用YouTube搜索API(v3),以便根据关键字搜索视频。它运作良好,这是我收到的一个例子:
{
"kind": "youtube#searchResult",
"etag": "\"dhbhlDw5j8dK10GxeV_UG6RSReM/hJdddtiTPMTxfi76U5-OfoXwfPE\"",
"id": {
"kind": "youtube#video",
"videoId": "TE9TpraPlrE"
},
"snippet": {
"publishedAt": "2010-06-29T17:00:38.000Z",
"channelId": "UCikzJG7RbnNZhKLqqaXRM6A",
"title": "What is SharePoint? | lynda.com overview",
"description": "This web development overview explores what SharePoint is and how it works. Watch more at ...",
"thumbnails": {
"default": {
"url": "https://i.ytimg.com/vi/TE9TpraPlrE/default.jpg"
},
"medium": {
"url": "https://i.ytimg.com/vi/TE9TpraPlrE/mqdefault.jpg"
},
"high": {
"url": "https://i.ytimg.com/vi/TE9TpraPlrE/hqdefault.jpg"
}
},
"channelTitle": "lyndapodcast",
"liveBroadcastContent": "none"
}
}
但是,我会遗漏一些信息,例如持续时间,频道的真实姓名和观看次数。我想还有另一个API入口点可以获取有关一个或多个视频的信息,但是可以在一次通话中获取所有这些信息吗?这意味着搜索API也会返回它们,或者我被迫总结搜索返回的所有视频,并再次拨打电话获取所有这些视频的信息?
答案 0 :(得分:1)
search不会返回持续时间,频道和观看次数。您需要将videoId
传递给video以获取所需信息。例如,使用videoId
Pxb5lSPLy9c
并设置part
以显示statistics
和contentDetails
将导致返回持续时间和观看次数。
请求:强>
GET https://www.googleapis.com/youtube/v3/videos?part=statistics%2C+contentDetails&id=Pxb5lSPLy9c&key={YOUR_API_KEY}
<强>响应:强>
{
"kind": "youtube#videoListResponse",
"etag": "\"dhbhlDw5j8dK10GxeV_UG6RSReM/2DniKZoxyNGn7I9fMnpuXArVy7I\"",
"pageInfo": {
"totalResults": 1,
"resultsPerPage": 1
},
"items": [
{
"kind": "youtube#video",
"etag": "\"dhbhlDw5j8dK10GxeV_UG6RSReM/866ffq8I1qvVuqduMHhbik3U_Ow\"",
"id": "Pxb5lSPLy9c",
"contentDetails": {
"duration": "PT9M18S",
"dimension": "2d",
"definition": "hd",
"caption": "true",
"licensedContent": true
},
"statistics": {
"viewCount": "3112372",
"likeCount": "125358",
"dislikeCount": "973",
"favoriteCount": "0",
"commentCount": "10242"
}
}
]
}