From 31b8ce9e0339f7061ff33d8992968ab1894c3573 Mon Sep 17 00:00:00 2001 From: longshuicy Date: Wed, 19 Apr 2017 17:12:53 -0500 Subject: [PATCH] youtube done need to pay attention to authentication! --- API/youtubeAPI.js | 58 +++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 56 insertions(+), 2 deletions(-) diff --git a/API/youtubeAPI.js b/API/youtubeAPI.js index 3c62a4d..640a9f3 100644 --- a/API/youtubeAPI.js +++ b/API/youtubeAPI.js @@ -10,6 +10,7 @@ var oauth2Client = new OAuth2( oauth2Client.setCredentials({ access_token: config.youtube.access_token, + refresh_token: config.youtube.refresh_token }); var youtube = google.youtube({ @@ -22,6 +23,7 @@ function youtubeAPI(resolveName, id, args){ switch(resolveName){ case 'search': + console.log(args) youtube.search.list({ part: 'id,snippet', key: config.youtube.api_key, @@ -59,19 +61,71 @@ function youtubeAPI(resolveName, id, args){ case 'channel': youtube.channels.list({ - part: 'auditDetails, brandingSettings,contentDetails, contentOwnerDetails,id,invideoPromotion,snippet,statistics,status,topicDetails', + part: 'invideoPromotion,brandingSettings,contentDetails,contentOwnerDetails,id,snippet,statistics,status,topicDetails', id: id }, function (err, data) { if (err){ console.log(err); reject(err); + }else{ + //console.log(data.items); + resolve(data.items); + } + }); + break; + + case 'video': + youtube.videos.list({ + part: `contentDetails,id,liveStreamingDetails,player, + recordingDetails,snippet,statistics,status,topicDetails`, + id: id + }, function (err, data) { + if (err){ + console.log(err); + reject(err); + }else{ + //console.log(data.items); + resolve(data.items); + } + }); + break; + + case 'videoCommentthread': + //console.log(args); + youtube.commentThreads.list({ + part:'id,snippet', + videoId: id, + maxResults: args['maxResults'], + searchTerms:args['searchTerms'] + }, function(err,data){ + if (err){ + console.log(err); + reject(err); + }else{ + //console.log(data.items); + resolve(data.items); + } + }); + break; + + case 'channelCommentthread': + console.log(args); + youtube.commentThreads.list({ + part:'id,snippet', + channelId: id, + maxResults: args['maxResults'], + searchTerms:args['searchTerms'] + }, function(err,data){ + if (err){ + console.log(err); + reject(err); }else{ console.log(data.items); resolve(data.items); } }); break; - } + } }) }