youtube-node icon indicating copy to clipboard operation
youtube-node copied to clipboard

self.addPart in #search doesn't work

Open danielravina opened this issue 8 years ago • 4 comments

Hi, I'm trying to add more parts to the search function with the following code but I don't see them in the results Code:

var YouTube = require('youtube-node');

var youTube = new YouTube();

youTube.setKey('AIzaSyB1OOSpTREs85WUMvIgJvLTZKye4BVsoFU');

youTube.addPart('contentDetails');
youTube.addPart('statistics');
youTube.addPart('status');

youTube.search('World War z Trailer', 2, function(error, result) {
  if (error) {
    console.log(error);
  }
  else {
    console.log(result);
  }
});

Result:

etag: "\"5g01s4-wS2b4VpScndqCYc5Y-8k/suscqJikhZQTuxqt_8zSu3fP_fA\""
id: Object {kind: "youtube#video", …}
kind: "youtube#searchResult"
snippet: {
  channelId: "UCkR0GY0ue02aMyM-oxwgg9g"
  channelTitle: "Movieclips Coming Soon"
  description: "Subscribe to TRAILERS: http://bit…://goo.gl/dHs73 Follow us on ..."
  liveBroadcastContent: "none"
  publishedAt: "2013-03-25T07:02:54.000Z"
  thumbnails: Object {default: , …}
  title: "World War Z TRAILER 2 (2013) - Brad Pitt Movie HD"
}

danielravina avatar Jun 30 '16 22:06 danielravina

NM ijust noticed the search endpoint only support the snippet. Is there a way to get a list of search results with more data?

danielravina avatar Jul 01 '16 03:07 danielravina

See https://developers.google.com/youtube/v3/docs/search/list

paulomcnally avatar Jul 02 '16 15:07 paulomcnally

I made a workaround with 2 api calls. I guess there isn't a way to get everything in one shot.

module.exports.search = (q) => {
  return new Promise((resolve, reject) => {
    youTube.search(q, 20, (error, result) => {
      if (error) return reject(error);

      const ids = result.items.map(r => r.id.videoId).join(',');

      youTube.getById(ids, (error, r) => {
        if (error) return reject(error);
        resolve(r);
      });
    });
  });
};

danielravina avatar Jul 02 '16 22:07 danielravina

Hi @danielravina have a pull request?

paulomcnally avatar Jul 02 '17 06:07 paulomcnally