2015-01-26 117 views

回答

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" 
    } 
    }, 
    { 

然後你就可以提取視頻ID創建的URL鏈接YouTube的視頻。

對於爲例items[0].id.videoId給我KG0vtEsiPgs

然後,你需要這個網址https://www.youtube.com/watch?v=來串聯videoId

https://www.youtube.com/watch?v= '視頻ID'

然後你有視頻鏈接。

+0

像魅力一樣工作......感謝一個好人! – user318197 2015-01-27 07:01:50