Youtube API Javascript Client Library objects returning undefined-Collection of common programming errors
I’m using the Javascript Client Library for a project, and for the most part it’s working fine with the exception of one little piece which I cannot figure out what is wrong for the life of me.
Here is the function with the problem (shortened):
function getVideoMetadata(videoIds) {
var request = gapi.client.youtube.videos.list({
id: videoIds.join(','),
part: 'id,contentDetails,player,snippet'
});
request.execute(function(response) {
if ('error' in response) {
// Error Handling
} else {
var td;
var responses = response.items;
jQuery.each(responses, function(index, item) {
td = document.createElement('td');
td.innerHtml = "
" + item.snippet.title + "
" + item.player.embedHtml.replace("640", "267").replace("360", "150") + "
" + item.snippet.description + "
";
The specification for the videos.list api call is here: https://developers.google.com/youtube/v3/docs/videos/list
In this function item.snippet.title, item.player, and item.snippet.description return undefined in all browsers, yet when debugging in VS they all have values in the immediate window. Also, when debugging in VS mousing over “title” will report undefined yet mousing over item returns an object with a snippet object. Expanding the snippet object reports a title field with an actual value. I do not know what the problem is, but am looking for some ideas.
Thanks,
Matt
Originally posted 2013-11-09 22:42:27.