I want to fetch a YouTube video title when the video id is known, using JavaScript only. Is it possible?
Asked
Active
Viewed 1.0k times
6
-
I thought the OP already has the video id and wants to fetch the *title* of the video (like, id is "099pb2c9pyg139p" and title is "Look at my funny cat"). – JJJ May 15 '12 at 08:28
-
hmm .. I already have video id.. I want to fetch video title... – Rukmi Patel May 15 '12 at 08:29
-
1We have this http://stackoverflow.com/questions/1216029/get-title-from-youtube-videos – James May 15 '12 at 08:36
-
1We have this http://stackoverflow.com/questions/1216029/get-title-from-youtube-videos – James May 15 '12 at 08:36
-
I have checked those likes .. no help.. I want to do this using JS only. – Rukmi Patel May 15 '12 at 08:41
-
Still a dupe of a dupe of a dupe :-) – PeeHaa May 15 '12 at 09:04
1 Answers
6
Yes, it is possible using Javascript and JSON.
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;
}
}