so I tried to put an embed youtube video to my index.html using google console API key, and this is the function that I made:
const searchVideos = async (key, search, maxResVideos) => {
const config = { params: { key: key, q: search } }
let res = await axios.get(`https://www.googleapis.com/youtube/v3/search?part=snippet&type=video&maxResVideos=${maxResVideos}`, config);
console.log('res:', res.data.items);
res.data.items.forEach(item => {
const video = document.createElement('div');
video.innerHTML = `<iframe width="560" height="315" src="https://www.youtube.com/embed/${item.id.videoId}" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>`;
searchResult.appendChild(video);
});
}
you can still make changes but this puts the embed video by creating a div and putting the iframe as string template literals ...