2015-02-09 70 views
0

如何讓我的最新的視頻ID作爲變量來使用這樣的:獲得最新的YouTube(抽搐)視頻網址

<script>//fetch newest video id and make it a variable</script> 
<button onclick="window.open('https://www.youtube.com/embed/'+videoId+'', 'newwindow', 'width=853, height=480'); return false;">My latest youtube video</button> 

like this but JS/JQUERY

,並沒有任何方法,這樣做是爲了抽搐過去的廣播嗎?

<button onclick="window.open('http://www.twitch.tv/User/popout?videoId='+streamId+'', 'newwindow', 'width=853, height=480'); return false;">My latest broadcast</button> 
+0

你爲什麼每兩分鐘就會搞砸這個問題。我正在回答你的問題。如果你不斷改變這個問題,你希望人們如何給你一個認真的答案? – NewToJS 2015-02-09 15:53:21

回答

0

我會建議使用Youtube API

YouTube Data API - Working with Channel IDs

這不僅給你所有的視頻ID,但是你必須對你如何在網站上顯示的視頻數據的控制。如果您想要更多地控制Youtube video player

YouTube JavaScript Player API Reference

Get Latest video from channel必須使用通道ID例如

https://www.youtube.com/channel/UC5yi93rwcQxIjr0s6Ak8mdw

視頻ID:UC5yi93rwcQxIjr0s6Ak8mdw

<html> 
<head> 
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script> 
<script type="text/javascript"> 
var i; 
function FolderData(ChanID){ 
    var ChanID=document.getElementById('YTCI').value; 
    $.ajax({ 
    url: 'http://gdata.youtube.com/feeds/base/users/'+ChanID+'/uploads?alt=json-in-script&v=2&orderby=published&max-results=1', 
    dataType: 'jsonp', 
    success: function(data){ 
     var vidID=data.feed.entry[0].id.$t.split("video:"); 
     document.getElementById('Results').innerHTML="Video ID: "+vidID[1]; 
     var YTbutton= document.getElementById("YTbtn"); 
     YTbutton.setAttribute("onclick","OpenWindow(\'https://www.youtube.com/embed/"+vidID[1]+"\');"); 
    }, 
     error: function() {console.log("Error");} 
    }); 
} 
function OpenWindow(Winpath){ 
window.open(Winpath, 'newwindow', 'width=853, height=480'); 
} 
</script> 
</head> 
<body> 
<input type="text" id="YTCI" placeholder="Channel ID"/><button onclick="FolderData()">Check Console</button> 
<div id="Results"></div> 
    <button id="YTbtn">My latest youtube video</button> 
</body> 
</html> 
0

我做了我所有的YouTube視頻播放,並採取了嵌入該播放列表的網址

<button onclick="window.open('https://www.youtube.com/embed/videoseries?list=PlaylistId', 'newwindow', 'width=853, height=480'); return false;">My latest youtube videos</button>