如何使用Node.js实现youtube.search.list

我正在尝试使youtube.search.listNode.js一起工作。 看起来我可以成功通过YouTube API v.3.0进行身份validation,但运行youtube.search.list我会得到空的结果集。

代码中有愚蠢的错误,或者我在YouTube API上做出错误的请求。

这里是代码:

 var google = require('googleapis'); var youtubeV3 = google.youtube({ version: 'v3', auth: 'MY_API_KEY' }); var request = youtubeV3.search.list({ part: 'snippet', type: 'video', q: 'Cat', maxResults: 50, order: 'date', safeSearch: 'moderate', videoEmbeddable: true }); // console.log('Here we start search'); for (var i in request.items) { var item = request.items[i]; console.log('Title: ', item.id.videoId, item.snippet.title); } 

为了检查我从API获取我运行console.log(request)并获得空对象。

有一点在API上摆弄,我想出了以下的工作代码:

 var google = require('googleapis'), youtubeV3 = google.youtube( { version: 'v3', auth: 'API_KEY' } ); var request = youtubeV3.search.list({ part: 'snippet', type: 'video', q: 'Cat', maxResults: 50, order: 'date', safeSearch: 'moderate', videoEmbeddable: true }, (err,response) => { // your code here }); 

尽pipe这里的文档告诉人们使用execute, 但是Github上的google apis仓库却告诉用户使用那个节点callback模式,结果certificate这是行得通的。