diff options
| author | Mohammad Amoush <mohammad_amoush@brown.edu> | 2019-06-26 17:54:16 -0400 |
|---|---|---|
| committer | Mohammad Amoush <mohammad_amoush@brown.edu> | 2019-06-26 17:54:16 -0400 |
| commit | 530f38e60d6289a221a463ba36af2ed22c15d8d2 (patch) | |
| tree | e26f8cb27b0d3920196bbe8899650e5dd85e971b /src/server/youtubeApi | |
| parent | b86050edd2da3acca258f117e8350aa8d53272d9 (diff) | |
Video Search Sample
Diffstat (limited to 'src/server/youtubeApi')
| -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 |
