I am only trying to fetch Youtube video's title. Can't seem to figure it. So far I have this:
q = 'https://www.googleapis.com/youtube/v3/videos?id='+ itemId +'&key='+ ytApiKey +'&fields=items(snippet(channelId,title,categoryId))&part=snippet' ;
$.ajax({
url: q,
dataType: "jsonp",
success: function(data){
alert(data.items[0].title);
console.log(data.snippet.title);
},
error: function(jqXHR, textStatus, errorThrown) {
alert (textStatus, + ' | ' + errorThrown);
}
});
Thanks,
I got it working using
https://www.googleapis.com/youtube/v3/videos?id=itemId&key=apiKey&fields=items(snippet(title))&part=snippet
and
alert(data.items[0].snippet.title);
So, not much wrong with the syntax! But I found that the problem was really in the backend when setting up the Google API's 'allowed referers'. With V3 API, you can select which referers the API should belong to, so others cannot simply steal your API and use it. So the API will work if the request is originated from the domain name/IP you specify. When I don't give it restrictions, the code works, but when I do enter my domain it fails! I entered .mydomainname.com/ , the same format as it was suggested, but it errors out somehow.. Now I've got figure out why.
The following jquery code will fetch the title of the video.
$.ajax({
url: "https://www.googleapis.com/youtube/v3/videos?id=" + videoId + "&key="+ apiKey + "&fields=items(snippet(title))&part=snippet",
dataType: "jsonp",
success: function(data){
console.log(data.items[0].snippet.title);
},
error: function(jqXHR, textStatus, errorThrown) {
alert (textStatus, + ' | ' + errorThrown);
}
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With