When a user inputs a YouTube video URL into my form, I want to automatically retrieve and display certain information from YouTube such as the title, description, and dimensions of the video. However, I'm struggling to find examples that demonstrate how to do this when the video ID is not known beforehand:
<script type="text/javascript" src =
"http://gdata.youtube.com/feeds/api/videos/<VideoID>?v=2&alt=json-in-script&callback=FeedCallback"
</script>
<script type="text/javascript">
function FeedCallback( data )
{
//get title from YouTube Data API via JSON
document.getElementById('Title').innerHTML = data.entry[ "title" ].$t;
}
</script>
Currently, the above script only works if the <VideoID>
is known at the time the view is loaded. Is there a way to dynamically determine the ID within the view and use that to fetch the required data?