我正在使用youtube-node npm查找所有视频列表。该文档位于链接https://www.npmjs.com/package/youtube-node。从nodejs的YouTube频道获取结果
但我想,我的搜索只显示特定通道即结果如果我搜索你好,那么它只能给AdeleVEVO YouTube频道的结果。 我找不到适合的文档。我不想使用oauth证书,我只想使用youtube-node npm。
我正在使用youtube-node npm查找所有视频列表。该文档位于链接https://www.npmjs.com/package/youtube-node。从nodejs的YouTube频道获取结果
但我想,我的搜索只显示特定通道即结果如果我搜索你好,那么它只能给AdeleVEVO YouTube频道的结果。 我找不到适合的文档。我不想使用oauth证书,我只想使用youtube-node npm。
在包文档中,您有样本搜索,请确保您在params参数中包含所需值的对象,在您的案例中,请参阅youtube api doc,您需要指定channelId。试试这种方式:
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));
}
})
;
如果您是该频道的所有者,则可以使用YouTube API的forMine参数。设置此参数将限制搜索授权用户的视频。以下是the official documentation的样本。
重要提示:不要使用youtube-node
模块对于这一点,特别是因为 - 在我的经验,至少 - 在addParam()
函数不可靠的参数添加到请求(例如,在我的代码我叫youtube_node.addParam('safeSearch', 'strict');
,但受限制的视频仍将返回结果中。)
请改为直接使用YouTube数据API,如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);
首先尝试使用youtube的本地API来查看是否有可能。之后,您可以使用一些节点包在应用程序中进行复制 –