Display Published Date and Category from YouTube Video

There are no errors in console but it’s not pulling the details too.

I have finally got it working. The only problem left is How can I get the Playlist Name? Here is my latest code:

<script type="text/javascript">
					window.onload = function () {
					var url = document.location.href,
						params = url.split('?')[1].split('&'),
						data = {}, tmp;
					for (var i = 0, l = params.length; i < l; i++) {
						 tmp = params[i].split('=');
						 data[tmp[0]] = tmp[1];
					}	
					 var videoId = data.vid;
					 var output = '<iframe width="420" height="315" src="https://www.youtube.com/embed/'+videoId+'"></iframe>';
					 document.getElementById('display').innerHTML = output;
					 
					 var id = videoId;
					 var url = 'https://www.youtube.com/watch?v=' + id;

					 $.getJSON('https://noembed.com/embed',
					 {format: 'json', url: url}, function (data) {
					 document.getElementById('vtitle').innerHTML=(data.title);					 
				});	
				
				$(document).ready(function(){
						$.getJSON('https://www.googleapis.com/youtube/v3/videos?part=snippet&id=' + videoId + '&key=AIzaSyA7dAzzNvPCxTSsSGiV7dvoj3rkt0qbdXg', function(data){
							$.each(data.items, function(i, item){
								var pub = item['snippet']['publishedAt'];
								var output1 = pub;
								
								document.getElementById('published').innerHTML = output1;
							});
						});
						
					});
				}





				</script>

Also, I need the date format: DD-MM-YYYY

You can use Date.parse() to turn it into a date object, and then use the different date methods such as getDate(), getMonth(), and getFullYear().

Beware, the getMonth() method gives you a 0-based index, so January is 0, February is 1, etc. That was designed so that you could easily display the name from an array, but isn’t all that user-friendly.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.