Skip to content

Instantly share code, notes, and snippets.

@AryanTYB
Last active December 16, 2021 13:13
Embed
What would you like to do?
Get YouTube videos of a channel
async function getYouTubeVideos() {
const youtubeApiKey = process.env.YOUTUBE_API_KEY // Get API key at https://console.cloud.google.com/marketplace/product/google/youtube.googleapis.com
const channelId = process.env.CHANNEL_ID
const numberOfVideos = 10
const youtubeQuery = await fetch(
`https://www.googleapis.com/youtube/v3/search?key=${youtubeApiKey}&channelId=${channelId}&part=snippet,id&order=date&maxResults=${numberOfVideos}`
)
const youtubeQueryRes = await youtubeQuery.json()
const videos = []
youtubeQueryRes.items.map((video) => {
videos.push({
title: video.snippet.title,
channel: video.snippet.channelTitle,
id: video.id.videoId,
thumbnail: video.snippet.thumbnails.medium,
publishedAt: video.snippet.publishedAt
})
})
return videos
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment