问题
I'm trying to retrieve details about YouTube videos using the V3 search API (https://www.googleapis.com/youtube/v3/search). I'm getting all the details of the videos in my JSON response but not the URLs of the videos. Can someone please help me on how to retrieve the URLs? Thanks in advance.
回答1:
There is no the video url in the JSON, you need to use the videoId.
For example you have a result like this one :
{
"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"
}
},
{
Then you can extract the videoId to create the url to link the YouTube video.
For exemple items[0].id.videoId
give me KG0vtEsiPgs
Then you need to concatenate the videoId
with this url https://www.youtube.com/watch?v=
:
https://www.youtube.com/watch?v='videoId'
Then you have the video link.
来源:https://stackoverflow.com/questions/28156527/how-to-retrieve-the-url-value-from-the-youtube-v3-api