Retrieving a YouTube video title using a well-known video ID

I want to get the YouTube video title when the video ID is known using only JavaScript. Is it possible?

+5
source share
1 answer

Yes, Javascript and JSON are possible.

https://developers.google.com/youtube/2.0/developers_guide_protocol_video_entries

See: https://developers.google.com/youtube/2.0/developers_guide_json

So you do it like this:

<script 
type="text/javascript" 
src="https://gdata.youtube.com/feeds/api/videos/videoid?v=2&alt=json-in-script&format=5&callback=getTitle">
</script>

And then:

function getTitle(data) {
 var feed = data.feed;
 var entries = feed.entry || [];
  for (var i = 0; i < entries.length; i++) {
   var entry = entries[i];
   var title = entry.title.$t;
  }
 } 
+5
source

All Articles