Skip to content

Instantly share code, notes, and snippets.

@LAMike310
Created March 26, 2016 20:18
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save LAMike310/bb0551bec95dd19e60bc to your computer and use it in GitHub Desktop.
Save LAMike310/bb0551bec95dd19e60bc to your computer and use it in GitHub Desktop.
Get all videos from a YouTube channel
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