Question

I can get the title and the video ID but I can't get the tumbnail. I keep getting an error that says "Missing name after . operator"

function doGet(e) {
  var app = UiApp.createApplication();
  var vPanel = app.createVerticalPanel();
  var myLabel = app.createLabel('My Favorite channel');
  vPanel.add(myLabel);

var results = YouTube.Search.list('id,snippet', {
channelId: 'UCDiFRMQWpcp8_KD4vwIVicw',
order:'date',
maxResults: 3
  });

for (var i = 0; i < results.items.length; i++) {
  var item = results.items[i];      
  var hPanel = app.createHorizontalPanel();
  hPanel.add(app.createLabel('Video ID: '+item.id.videoId+' Video Title: '+item.snippet.title));
  hPanel.add(app.createImage(item.snippet.thumbnails.default.url));
  vPanel.add(hPanel);
  }

  app.add(vPanel);
  return app

}
Was it helpful?

Solution

Since you have the video ID, you can directly get the URL of the thumbnail using a simple URL hack.

hPanel.add(app.createLabel('Video ID: '+item.id.videoId+' Video Title: '+item.snippet.title));
hPanel.add(app.createImage('http://img.youtube.com/vi/' + item.id.videoId + '/mqdefault.jpg'));

You can replace mqdefault.jpq with hqdefault.jpg for high-quality thumbnails.

OTHER TIPS

I think a more robust solution than that suggested by @Amit would be to directly reference the url field in the video resource object, like so:

hPanel.add(app.createImage(item.snippet.thumbnails['default'].url));
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top