search-pages.js
1.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
var YouTube = require('../lib/youtube');
var config = require('./config');
var youTube = new YouTube();
youTube.setKey(config.key);
var query = 'World War z Trailer';
youTube.search(query, 5, function(error, result) {
if (error) {
console.log(error);
}
else {
var perPage = 50;
var videos = [];
//todo: there's a better way of doing this - with async lib
youTube.search(query, perPage, {pageToken: result.nextPageToken} , function(error, result) {
console.log('Next Page Token = '+result.nextPageToken);
result.items.forEach(function(video){
videos.push(video);
});
youTube.search(query, perPage, {pageToken: result.nextPageToken} , function(error, result) {
console.log('Next Page Token = '+result.nextPageToken);
result.items.forEach(function(video){
videos.push(video);
});
youTube.search(query, perPage, {pageToken: result.nextPageToken} , function(error, result) {
console.log('Next Page Token = '+result.nextPageToken);
result.items.forEach(function(video){
videos.push(video);
});
youTube.search(query, perPage, {pageToken: result.nextPageToken} , function(error, result) {
console.log('Next Page Token = '+result.nextPageToken);
result.items.forEach(function(video){
videos.push(video);
});
youTube.search(query, perPage, {pageToken: result.nextPageToken} , function(error, result) {
console.log('Next Page Token = '+result.nextPageToken);
result.items.forEach(function(video){
videos.push(video);
});
console.log('Total # of videos = '+ videos.length)
});
});
});
});
});
}
});