I am trying to get data from a YouTube channel using Youtube API V3. The code below fetches various data points but when I tried running the app I did not see the payload ('items') array in my response object nor did I get an 'error'. This is what I saw instead:
{ kind: 'youtube#channelListResponse', etag: 'PqCO86vmlUDWFiOBSqOsOZRp5jE', pageInfo: { totalResults: 0, resultsPerPage: 50 }}
My code looks like this - what am I doing wrong?
const Youtube = ({ youtubeDataJson }) => { console.log(youtubeDataJson); return (<><div><h1>This should log the data</h1></div></> );};export async function getServerSideProps(context) { //Base Url const gBaseUrl = "https://www.googleapis.com/youtube/v3"; const channelName = "ThePrimeagen"; // fetching data const youtubeData = await fetch( `${gBaseUrl}/channels?part=snippet&part=contentDetails&part=statistics&part=contentOwnerDetails&forUsername=${channelName}&maxResults=50&key=${process.env.YOUTUBE_API_KEY}` ); const youtubeDataJson = await youtubeData.json(); //Return data return { props: { youtubeDataJson } };}export default Youtube;