test.js
1.59 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
//https://developers.google.com/youtube/v3/docs/commentThreads/list
//http://khuhub.khu.ac.kr/2019102147/youtube-comment-seperator.git
const apiKey = 'AIzaSyCjBrFKnBlGvxsfOD-qJP8nBkdEoqKRHu8';
let videoNum = "m1gHR4dJhKU";
const {google} = require("googleapis");
const service = google.youtube('v3');
var npt = ""
for(let i = 0; i < 3; i++){
console.log(npt);
service.commentThreads.list({
"key":apiKey,
"part":[
"snippet, replies"
],
"videoId":videoNum,//비디오 주소
"maxResults" : 10,
"pageToken" : npt
}).then(function(response) {
console.log("Response", response);
console.log(response.data.items[0].snippet.topLevelComment.snippet.textDisplay);
console.log(response.data.items[1].snippet.topLevelComment.snippet.textDisplay);
npt = JSON.parse(response.data.nextPageToken);
},
function(err) { console.error("Execute error", err); });
}
/*
service.comments.list({
"key": apiKey,
"part": [
"snippet"
],
"parentId": "UgzDE2tasfmrYLyNkGt4AaABAg"
}).then(function(response) {
// Handle the results here (response.result has the parsed body).
console.log("Response", response);
console.log(response.data.items)
},
function(err) { console.error("Execute error", err); });
const {YoutubeDataAPI} = require("youtube-v3-api");
const {google} = require("googleapis");
const api = new YoutubeDataAPI(apiKey);
api.searchComments("https://youtu.be/m1gHR4dJhKU").then((data)=>{
console.log(data);
console.log(data.pageInfo);
},(err)=>{
console.error(err);
})
*/