I am fetching playlistItems from the Youtube Data API via this URL:
URL = `https://youtube.googleapis.com/youtube/v3/playlistItems?part=snippet%2C%20contentDetails&playlistId=${playlistId}&maxResults=${50}&pageToken=${nextPageToken}&key=${API_KEY}`
it works fine in a project I'm using for experimentation.
Now it was time to copy the code into my actual application.
The only thing I changed was that I put the API_Key inside my .env and set it via:
const API_KEY = process.env.YT_API_KEY
I still don't understand why, but the URL ends up having key=undefined at the end:
I am setting it inside .env like this:
Now to the real reason why I'm seeking help: To fix the issue, I set the API_KEY directly inside the file that makes the fetch.
But I get the same 401 error as above (except key= is not undefined anymore)
And when I click the link in the error message, I can look at the JSON object, that I seek. So the URL is definitely working. As it (still) does in my other project.
So what leads to the 401 error then?
I had the idea, that maybe I need to change something in the cloud platform credentials settings. But my API key doesn't have any restrictions.