Reputation: 1356
I'm trying to make youtube.search.list
working with Node.js
. It looks like I can successfully authenticate with YouTube API
v.3.0 but when I run youtube.search.list
I get empty result set.
There is either stupid error in the code or I make incorrect request on YouTube API
.
Here is the code:
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);
}
In order to check what I get back from API I run console.log(request)
and get empty object.
Upvotes: 1
Views: 2202
Reputation: 74046
Fiddeling around with the API a little, I came up with the following, working code:
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
});
Despite the documentation here telling one to use execute, the repository of google apis on Github tells one to use that node callback pattern, which turned out to work.
Upvotes: 2