나혜원

update youtube.js

1 var response = 'IU'; 1 var response = 'IU';
2 2
3 -var request = require("request"); 3 +var request = require('request');
4 +var cheerio = require('cheerio');
4 5
5 var options = { method: 'GET', 6 var options = { method: 'GET',
6 url: 'https://www.googleapis.com/youtube/v3/search', 7 url: 'https://www.googleapis.com/youtube/v3/search',
7 qs: 8 qs:
8 { key: 'AIzaSyA8-HR7V5cGIwWiBUWzKZsm5yzwrYc-4ys', 9 { key: 'AIzaSyA8-HR7V5cGIwWiBUWzKZsm5yzwrYc-4ys',
9 - part: 'snippet', 10 + part: 'id',
10 maxResults: '1', 11 maxResults: '1',
11 order: 'viewCount', 12 order: 'viewCount',
12 q: response, 13 q: response,
13 type: 'video' }, 14 type: 'video' },
14 }; 15 };
15 16
16 -request(options, function (error, response, body) { 17 +request(options, function(error,result,body){
17 - if (error) throw new Error(error); 18 + if(error) throw new Error(error);
18 19
19 - console.log(body); 20 + var temp = body.replace('{','');
21 + var temp1 = temp.split('\n');
22 +
23 + console.log(temp1);
20 }); 24 });
...\ No newline at end of file ...\ No newline at end of file
......