I am doing validation for my Youtube url text field.
I need to check, if the Youtube url does not exist I should throw error, I followed this answer an
For those who are looking for a solution using the V3 API, you can do the following:
var videoID = 'the_youtube_video_id';
$.getJSON('https://www.googleapis.com/youtube/v3/videos?id=' + videoID
+ "&key=INSERT_YOUR_API_KEY_HERE&part=COMMA_DELIMITED_VALUE",
function (data, status, xhr) {
if (data.items.length > 0)
alert('It is there!')
else
alert('Are you sure you about the Id?');
console.log(status);
console.log(xhr);
}).error(function (xhr, errorType, exception) {
var errorMessage = exception || xhr.statusText || xhr.responseText;
alert(errorMessage);
});
For a list of valid parts you may visit the doc page here.