我正在尝试使用V3搜索API(https://www.googleapis.com/youtube/v3/search)检索有关YouTube视频的详细信息。我在JSON响应中获取了视频的所有详细信息,但没有获取视频的网址。有人可以帮我解决如何检索URL的问题吗?提前谢谢。
答案 0 :(得分:2)
JSON中没有视频网址,您需要使用videoId。
例如,你有一个像这样的结果:
{
"kind": "youtube#searchListResponse",
"etag": "\"F9iA7pnxqNgrkOutjQAa9F2k8HY/KciEh2k6bPhgTexCFr55nrDyEuo\"",
"nextPageToken": "CAUQAA",
"pageInfo": {
"totalResults": 1031,
"resultsPerPage": 5
},
"items": [
{
"kind": "youtube#searchResult",
"etag": "\"F9iA7pnxqNgrkOutjQAa9F2k8HY/1Y85a6l1YSEQprOw66ptMsh0Bzw\"",
"id": {
"kind": "youtube#video",
"videoId": "KG0vtEsiPgs"
},
"snippet": {
"publishedAt": "2015-01-04T20:06:53.000Z",
"channelId": "UC5nc_ZtjKW1htCVZVRxlQAQ",
"title": "Real Slow - You Flow",
"description": "That little vocal snippet has got me hooked :) Download... http://bit.ly/1xHDPlX Real Slow https://soundcloud.com/realslowbeats ...",
"thumbnails": {
"default": {
"url": "https://i.ytimg.com/vi/KG0vtEsiPgs/default.jpg"
},
"medium": {
"url": "https://i.ytimg.com/vi/KG0vtEsiPgs/mqdefault.jpg"
},
"high": {
"url": "https://i.ytimg.com/vi/KG0vtEsiPgs/hqdefault.jpg"
}
},
"channelTitle": "MrSuicideSheep",
"liveBroadcastContent": "none"
}
},
{
然后,您可以提取videoId以创建链接YouTube视频的网址。
例如items[0].id.videoId
给我 KG0vtEsiPgs
然后您需要将videoId
与此网址https://www.youtube.com/watch?v=
连接起来:
https://www.youtube.com/watch?v=' VIDEOID'
然后你有了视频链接。