Created
December 16, 2021 13:13
-
-
Save Uvacoder/eb607c47c4c8481ac65c58a8f688217c to your computer and use it in GitHub Desktop.
Get YouTube videos of a channel
This file contains hidden or 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
| 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