Created
March 26, 2016 20:18
-
-
Save LAMike310/bb0551bec95dd19e60bc to your computer and use it in GitHub Desktop.
Get all videos from a YouTube channel
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var axios = require('axios') | |
var Firebase = require('firebase') | |
var nextPageToken = '' | |
// Get the YT Channel Playlist ID from here: | |
// https://www.googleapis.com/youtube/v3/channels?part=contentDetails&forUsername={YOUTUBE_CHANNEL_NAME}&key={YOUR_API_KEY} | |
function saveVideoData(token) { | |
var ROOT_URL = "https://www.googleapis.com/youtube/v3/playlistItems?pageToken=" + nextPageToken + "&part=snippet&playlistId=UUzQUP1qoWDoEbmsQxvdjxgQ&key={YOUR_API_KEY}&maxResults=50&?" | |
axios.get(ROOT_URL) | |
.then(function (response) { | |
data = response.data; | |
if(response.data.nextPageToken == undefined) { | |
exampleRef = new Firebase("https://{your_firebase}.firebaseio.com/youtubeData/") | |
exampleRef.push(data) | |
console.log("All done!") | |
return false | |
} | |
else { | |
nextPageToken = response.data.nextPageToken | |
console.log("nextPageToken: " + nextPageToken); | |
exampleRef = new Firebase("https://{your_firebase}.firebaseio.com/youtubeData/") | |
exampleRef.push(data) | |
saveVideoData(nextPageToken) | |
} | |
}) | |
.catch(function (response) { | |
console.log(response); | |
}); | |
} | |
saveVideoData(nextPageToken) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment