2014-10-17 135 views
9

我使用YouTube數據API版本3,讓高層YouTube視頻,我調用REST API是這樣的:YouTube數據API V3 - 無視頻網址

https://developers.google.com/apis-explorer/#p/youtube/v3/youtube.search.list?part=snippet&forMine=true&maxResults=10&order=viewCount&type=video&_h=6&

,並得到這樣的數據這是JSON格式:

"kind": "youtube#searchResult", 
"etag": "adasdasdasdasdas", 
"id": 
{ 
    "kind": "youtube#video", 
    "videoId": "123123asdsad12" 
}, 
"snippet": 
{ 
    "publishedAt": "date", 
    "channelId": "Gasdqqweqweqwr123123", 
    "title": "my tutle", 
    "description": "xyz", 
    "thumbnails": 
    { 
    "default": 
    { 
     "url": "......jpg", 
     "width": 120, 
     "height": 90 
    }, 
    "medium": 
    { 
     "url": "......jpg", 
     "width": 320, 
     "height": 180 
    }, 
    "high": 
    { 
     "url": "......jpg", 
     "width": 480, 
     "height": 360 
    } 
    }, 
    "liveBroadcastContent": "none" 
} 

但這個數據不包含youtube視頻網址,我怎麼能從api獲取它?

回答

30

你可以有視頻的網址是這樣的:

您有結果:

 "kind": "youtube#searchResult", 
"etag": "\"adasdasdasdasdas"", 
"id": { 
"kind": "youtube#video", 
"videoId": "123123asdsad12" 
}, 
... 

現在,你外地"videoId": "123123asdsad12"

,您可以查看在通過鏈接的視頻:

https://www.youtube.com/watch?v=123123asdsad12

就是這樣!

上查詢
+0

感謝名單,它的工作:) – 2014-10-17 18:11:22

+0

有沒有辦法得到充分的鏈接程序?我們有可以確定的id,但是如果鏈接格式更改爲「id」而不是「v」,該怎麼辦?像「https://www.youtube.com/watch?id=123123asdsad12」 – 2015-05-20 09:34:28

+0

它'v'廣告時,它永遠不會改變:) – mpgn 2015-05-20 10:11:50

1

,「份」屬性實際上表明你想要什麼樣的信息調用返回的「片段」 valie會返回一個更詳細的信息。對於每個結果,如果你想在「視頻ID」的數據做下面,在「零件」屬性上添加「id」值,如下所示:...?part = snippet,id & ...

這將獲得包含videoID信息的數據。

關於。