diff options
Diffstat (limited to 'src/server/youtubeApi/youtubeApiSample.js')
| -rw-r--r-- | src/server/youtubeApi/youtubeApiSample.js | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/src/server/youtubeApi/youtubeApiSample.js b/src/server/youtubeApi/youtubeApiSample.js index 7d5c936f5..35d74c62f 100644 --- a/src/server/youtubeApi/youtubeApiSample.js +++ b/src/server/youtubeApi/youtubeApiSample.js @@ -23,11 +23,16 @@ module.exports.readApiKey = (callback) => { module.exports.authorizedGetChannel = (apiKey) => { //this didnt get called - console.log("I get called"); + console.log("I get called ", apiKey); + console.log(TOKEN_PATH); // Authorize a client with the loaded credentials, then call the YouTube API. authorize(JSON.parse(apiKey), getChannel); } +module.exports.authorizedGetVideos = (apiKey) => { + authorize(JSON.parse(apiKey), getSampleVideos); +} + /** * Create an OAuth2 client with the given credentials, and then execute the @@ -132,4 +137,22 @@ function getChannel(auth) { channels[0].statistics.viewCount); } }); +} + +function getSampleVideos(auth) { + let service = google.youtube('v3'); + service.search.list({ + auth: auth, + part: 'id, snippet', + type: 'video', + q: 'istanbul', + maxResults: 3 + }, function (err, response) { + if (err) { + console.log('The API returned an error: ' + err); + return; + } + let videos = response.data.items; + console.log('Videos found: ' + videos[0].id.videoId, " ", videos[0].snippet.title); + }); }
\ No newline at end of file |
