Lal Rishav
Lal Rishav

Reputation: 1

Get result in from YouTube channel in nodejs

I am using youtube-node npm to find out all the video list. The documentation is on the link https://www.npmjs.com/package/youtube-node.

But I want that my search only show result of a specific channel i.e if I search hello, then it only give result of AdeleVEVO YouTube channel. I cant find suitable documentation for that. I don't want to use oauth credentials, I only want to use youtube-node npm.

Upvotes: 0

Views: 1568

Answers (2)

rotarydial
rotarydial

Reputation: 2581

If you are the owner of the channel, you can use the forMine parameter of the YouTube API for this. Setting this parameter will limit the search to the authorized user's videos. Below is a sample from the official documentation.

IMPORTANT NOTE: Do not use the youtube-node module for this, specifically because--in my experience at least--the addParam() function does not reliably add parameters to the request (e.g., in my code I called youtube_node.addParam('safeSearch', 'strict');, but restricted videos would still be returned in the results.)

Instead, use the YouTube Data API directly as shown in this quickstart example.

  // Sample nodejs code for search.list

  function searchListMine(auth, requestData) {
    var service = google.youtube('v3');
    var parameters = removeEmptyParameters(requestData['params']);
    parameters['auth'] = auth;
    service.search.list(parameters, function(err, response) {
      if (err) {
        console.log('The API returned an error: ' + err);
        return;
      }
      console.log(response);
    });
  }

  //See full code sample for authorize() function code.
  authorize(JSON.parse(content), {'params': {'maxResults': '25',
                   'forMine': 'true',
                   'part': 'snippet',
                   'q': 'fun',
                   'type': 'video'}}, searchListMine);

Upvotes: 0

Andro Font
Andro Font

Reputation: 356

In package doc you have a sample search, make sure you include in the params parameter an object with the values you want, in your case see in youtube api doc that you need to specify the channelId. Try this way:

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

var youTube = new YouTube();

youTube.setKey('AIzaSyB1OOSpTREs85WUMvIgJvLTZKye4BVsoFU');

youTube.search('World War z Trailer', 2, {channelId: <string value of the channelId>}, function(error, result) {
  if (error) {
    console.log(error);
  }
  else {
    console.log(JSON.stringify(result, null, 2));
  }
})

;

Upvotes: 1

Related Questions